about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2015-12-15 00:03:42 +0100
committerFlorian Hahn <flo@fhahn.com>2015-12-18 13:32:14 +0100
commitde3e843d2467dff3ccb83efbae9260dc1b2a40bf (patch)
tree296aa9288270388391d96df8386f3437cbf8ac02 /src
parentca52c56e346a2a2bb042bec441b5058df3e3e289 (diff)
downloadrust-de3e843d2467dff3ccb83efbae9260dc1b2a40bf.tar.gz
rust-de3e843d2467dff3ccb83efbae9260dc1b2a40bf.zip
Use memchr in libstd where possible, closes #30076
Diffstat (limited to 'src')
-rw-r--r--src/libstd/ffi/c_str.rs3
-rw-r--r--src/libstd/io/buffered.rs3
-rw-r--r--src/libstd/io/mod.rs3
-rw-r--r--src/libstd/sys/unix/os.rs3
4 files changed, 8 insertions, 4 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 318ff410cba..3f3913471b8 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -19,6 +19,7 @@ use io;
 use iter::Iterator;
 use libc;
 use mem;
+use memchr;
 use ops::Deref;
 use option::Option::{self, Some, None};
 use os::raw::c_char;
@@ -188,7 +189,7 @@ impl CString {
     }
 
     fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
-        match bytes.iter().position(|x| *x == 0) {
+        match memchr::memchr(0, &bytes) {
             Some(i) => Err(NulError(i, bytes)),
             None => Ok(unsafe { CString::from_vec_unchecked(bytes) }),
         }
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs
index 90a79da3483..79eedbeda2c 100644
--- a/src/libstd/io/buffered.rs
+++ b/src/libstd/io/buffered.rs
@@ -18,6 +18,7 @@ use cmp;
 use error;
 use fmt;
 use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
+use memchr;
 
 /// The `BufReader` struct adds buffering to any reader.
 ///
@@ -746,7 +747,7 @@ impl<W: Write> LineWriter<W> {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<W: Write> Write for LineWriter<W> {
     fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
-        match buf.iter().rposition(|b| *b == b'\n') {
+        match memchr::memrchr(b'\n', buf) {
             Some(i) => {
                 let n = try!(self.inner.write(&buf[..i + 1]));
                 if n != i + 1 { return Ok(n) }
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index efe40cf07c1..cc3f8097a88 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -254,6 +254,7 @@ use result;
 use string::String;
 use str;
 use vec::Vec;
+use memchr;
 
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use self::buffered::{BufReader, BufWriter, LineWriter};
@@ -1194,7 +1195,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
                 Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                 Err(e) => return Err(e)
             };
-            match available.iter().position(|x| *x == delim) {
+            match memchr::memchr(delim, available) {
                 Some(i) => {
                     buf.extend_from_slice(&available[..i + 1]);
                     (true, i + 1)
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index c2bf0651cff..12b9d6191a0 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -22,6 +22,7 @@ use io;
 use iter;
 use libc::{self, c_int, c_char, c_void};
 use mem;
+use memchr;
 use path::{self, PathBuf};
 use ptr;
 use slice;
@@ -406,7 +407,7 @@ pub fn env() -> Env {
         if input.is_empty() {
             return None;
         }
-        let pos = input[1..].iter().position(|&b| b == b'=').map(|p| p + 1);
+        let pos = memchr::memchr(b'=', &input[1..]).map(|p| p + 1);
         pos.map(|p| (
             OsStringExt::from_vec(input[..p].to_vec()),
             OsStringExt::from_vec(input[p+1..].to_vec()),