@@ -24,77 +24,117 @@ use vec::Vec;
2424
2525#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2626impl < ' a , R : Read + ?Sized > Read for & ' a mut R {
27+ #[ inline]
2728 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
2829 ( * * self ) . read ( buf)
2930 }
31+
32+ #[ inline]
3033 fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
3134 ( * * self ) . read_to_end ( buf)
3235 }
36+
37+ #[ inline]
3338 fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
3439 ( * * self ) . read_to_string ( buf)
3540 }
3641}
3742#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3843impl < ' a , W : Write + ?Sized > Write for & ' a mut W {
44+ #[ inline]
3945 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > { ( * * self ) . write ( buf) }
46+
47+ #[ inline]
4048 fn flush ( & mut self ) -> io:: Result < ( ) > { ( * * self ) . flush ( ) }
49+
50+ #[ inline]
4151 fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
4252 ( * * self ) . write_all ( buf)
4353 }
54+
55+ #[ inline]
4456 fn write_fmt ( & mut self , fmt : fmt:: Arguments ) -> io:: Result < ( ) > {
4557 ( * * self ) . write_fmt ( fmt)
4658 }
4759}
4860#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4961impl < ' a , S : Seek + ?Sized > Seek for & ' a mut S {
62+ #[ inline]
5063 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > { ( * * self ) . seek ( pos) }
5164}
5265#[ stable( feature = "rust1" , since = "1.0.0" ) ]
5366impl < ' a , B : BufRead + ?Sized > BufRead for & ' a mut B {
67+ #[ inline]
5468 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > { ( * * self ) . fill_buf ( ) }
69+
70+ #[ inline]
5571 fn consume ( & mut self , amt : usize ) { ( * * self ) . consume ( amt) }
72+
73+ #[ inline]
5674 fn read_until ( & mut self , byte : u8 , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
5775 ( * * self ) . read_until ( byte, buf)
5876 }
77+
78+ #[ inline]
5979 fn read_line ( & mut self , buf : & mut String ) -> io:: Result < usize > {
6080 ( * * self ) . read_line ( buf)
6181 }
6282}
6383
6484#[ stable( feature = "rust1" , since = "1.0.0" ) ]
6585impl < R : Read + ?Sized > Read for Box < R > {
86+ #[ inline]
6687 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
6788 ( * * self ) . read ( buf)
6889 }
90+
91+ #[ inline]
6992 fn read_to_end ( & mut self , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
7093 ( * * self ) . read_to_end ( buf)
7194 }
95+
96+ #[ inline]
7297 fn read_to_string ( & mut self , buf : & mut String ) -> io:: Result < usize > {
7398 ( * * self ) . read_to_string ( buf)
7499 }
75100}
76101#[ stable( feature = "rust1" , since = "1.0.0" ) ]
77102impl < W : Write + ?Sized > Write for Box < W > {
103+ #[ inline]
78104 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > { ( * * self ) . write ( buf) }
105+
106+ #[ inline]
79107 fn flush ( & mut self ) -> io:: Result < ( ) > { ( * * self ) . flush ( ) }
108+
109+ #[ inline]
80110 fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
81111 ( * * self ) . write_all ( buf)
82112 }
113+
114+ #[ inline]
83115 fn write_fmt ( & mut self , fmt : fmt:: Arguments ) -> io:: Result < ( ) > {
84116 ( * * self ) . write_fmt ( fmt)
85117 }
86118}
87119#[ stable( feature = "rust1" , since = "1.0.0" ) ]
88120impl < S : Seek + ?Sized > Seek for Box < S > {
121+ #[ inline]
89122 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > { ( * * self ) . seek ( pos) }
90123}
91124#[ stable( feature = "rust1" , since = "1.0.0" ) ]
92125impl < B : BufRead + ?Sized > BufRead for Box < B > {
126+ #[ inline]
93127 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > { ( * * self ) . fill_buf ( ) }
128+
129+ #[ inline]
94130 fn consume ( & mut self , amt : usize ) { ( * * self ) . consume ( amt) }
131+
132+ #[ inline]
95133 fn read_until ( & mut self , byte : u8 , buf : & mut Vec < u8 > ) -> io:: Result < usize > {
96134 ( * * self ) . read_until ( byte, buf)
97135 }
136+
137+ #[ inline]
98138 fn read_line ( & mut self , buf : & mut String ) -> io:: Result < usize > {
99139 ( * * self ) . read_line ( buf)
100140 }
@@ -105,6 +145,7 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
105145
106146#[ stable( feature = "rust1" , since = "1.0.0" ) ]
107147impl < ' a > Read for & ' a [ u8 ] {
148+ #[ inline]
108149 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
109150 let amt = cmp:: min ( buf. len ( ) , self . len ( ) ) ;
110151 let ( a, b) = self . split_at ( amt) ;
@@ -116,12 +157,16 @@ impl<'a> Read for &'a [u8] {
116157
117158#[ stable( feature = "rust1" , since = "1.0.0" ) ]
118159impl < ' a > BufRead for & ' a [ u8 ] {
160+ #[ inline]
119161 fn fill_buf ( & mut self ) -> io:: Result < & [ u8 ] > { Ok ( * self ) }
162+
163+ #[ inline]
120164 fn consume ( & mut self , amt : usize ) { * self = & self [ amt..] ; }
121165}
122166
123167#[ stable( feature = "rust1" , since = "1.0.0" ) ]
124168impl < ' a > Write for & ' a mut [ u8 ] {
169+ #[ inline]
125170 fn write ( & mut self , data : & [ u8 ] ) -> io:: Result < usize > {
126171 let amt = cmp:: min ( data. len ( ) , self . len ( ) ) ;
127172 let ( a, b) = mem:: replace ( self , & mut [ ] ) . split_at_mut ( amt) ;
@@ -130,6 +175,7 @@ impl<'a> Write for &'a mut [u8] {
130175 Ok ( amt)
131176 }
132177
178+ #[ inline]
133179 fn write_all ( & mut self , data : & [ u8 ] ) -> io:: Result < ( ) > {
134180 if try!( self . write ( data) ) == data. len ( ) {
135181 Ok ( ( ) )
@@ -138,20 +184,87 @@ impl<'a> Write for &'a mut [u8] {
138184 }
139185 }
140186
187+ #[ inline]
141188 fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
142189}
143190
144191#[ stable( feature = "rust1" , since = "1.0.0" ) ]
145192impl Write for Vec < u8 > {
193+ #[ inline]
146194 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
147195 self . push_all ( buf) ;
148196 Ok ( buf. len ( ) )
149197 }
150198
199+ #[ inline]
151200 fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
152201 self . push_all ( buf) ;
153202 Ok ( ( ) )
154203 }
155204
205+ #[ inline]
156206 fn flush ( & mut self ) -> io:: Result < ( ) > { Ok ( ( ) ) }
157207}
208+
209+ #[ cfg( test) ]
210+ mod tests {
211+ use io:: prelude:: * ;
212+ use vec:: Vec ;
213+ use test;
214+
215+ #[ bench]
216+ fn bench_read_slice ( b : & mut test:: Bencher ) {
217+ let buf = [ 5 ; 1024 ] ;
218+ let mut dst = [ 0 ; 128 ] ;
219+
220+ b. iter ( || {
221+ let mut rd = & buf[ ..] ;
222+ for _ in ( 0 .. 8 ) {
223+ let _ = rd. read ( & mut dst) ;
224+ test:: black_box ( & dst) ;
225+ }
226+ } )
227+ }
228+
229+ #[ bench]
230+ fn bench_write_slice ( b : & mut test:: Bencher ) {
231+ let mut buf = [ 0 ; 1024 ] ;
232+ let src = [ 5 ; 128 ] ;
233+
234+ b. iter ( || {
235+ let mut wr = & mut buf[ ..] ;
236+ for _ in ( 0 .. 8 ) {
237+ let _ = wr. write_all ( & src) ;
238+ test:: black_box ( & wr) ;
239+ }
240+ } )
241+ }
242+
243+ #[ bench]
244+ fn bench_read_vec ( b : & mut test:: Bencher ) {
245+ let buf = vec ! [ 5 ; 1024 ] ;
246+ let mut dst = [ 0 ; 128 ] ;
247+
248+ b. iter ( || {
249+ let mut rd = & buf[ ..] ;
250+ for _ in ( 0 .. 8 ) {
251+ let _ = rd. read ( & mut dst) ;
252+ test:: black_box ( & dst) ;
253+ }
254+ } )
255+ }
256+
257+ #[ bench]
258+ fn bench_write_vec ( b : & mut test:: Bencher ) {
259+ let mut buf = Vec :: with_capacity ( 1024 ) ;
260+ let src = [ 5 ; 128 ] ;
261+
262+ b. iter ( || {
263+ let mut wr = & mut buf[ ..] ;
264+ for _ in ( 0 .. 8 ) {
265+ let _ = wr. write_all ( & src) ;
266+ test:: black_box ( & wr) ;
267+ }
268+ } )
269+ }
270+ }
0 commit comments