diff options
| author | Jeremy Soller <jackpot51@gmail.com> | 2016-12-12 14:55:09 -0700 |
|---|---|---|
| committer | Jeremy Soller <jackpot51@gmail.com> | 2016-12-12 14:55:09 -0700 |
| commit | 7e7775ce7bfc916ce723bd1fdaf4ae54662c6627 (patch) | |
| tree | 235a9c38e42bacdb671da33bc49ffc8a4aba17a4 /src/libstd/io | |
| parent | c61baa0fc7a85bd2bcce34aac05ed739261cf037 (diff) | |
| parent | 6483bdd860fd89fc68846d4cc94c7ae3307a84c1 (diff) | |
| download | rust-7e7775ce7bfc916ce723bd1fdaf4ae54662c6627.tar.gz rust-7e7775ce7bfc916ce723bd1fdaf4ae54662c6627.zip | |
Merge branch 'master' into redox
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/impls.rs | 22 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 6b26c016638..f691289811b 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -157,7 +157,16 @@ impl<'a> Read for &'a [u8] { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { let amt = cmp::min(buf.len(), self.len()); let (a, b) = self.split_at(amt); - buf[..amt].copy_from_slice(a); + + // First check if the amount of bytes we want to read is small: + // `copy_from_slice` will generally expand to a call to `memcpy`, and + // for a single byte the overhead is significant. + if amt == 1 { + buf[0] = a[0]; + } else { + buf[..amt].copy_from_slice(a); + } + *self = b; Ok(amt) } @@ -169,7 +178,16 @@ impl<'a> Read for &'a [u8] { "failed to fill whole buffer")); } let (a, b) = self.split_at(buf.len()); - buf.copy_from_slice(a); + + // First check if the amount of bytes we want to read is small: + // `copy_from_slice` will generally expand to a call to `memcpy`, and + // for a single byte the overhead is significant. + if buf.len() == 1 { + buf[0] = a[0]; + } else { + buf.copy_from_slice(a); + } + *self = b; Ok(()) } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ad9ae5638b6..b3b89213df1 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -256,7 +256,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use cmp; -use rustc_unicode::str as core_str; +use std_unicode::str as core_str; use error as std_error; use fmt; use result; |
