Use memchr in libstd where possible, closes #30076
This commit is contained in:
parent
ca52c56e34
commit
de3e843d24
4 changed files with 8 additions and 4 deletions
|
@ -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) }),
|
||||
}
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue