Use memchr in libstd where possible, closes #30076

This commit is contained in:
Florian Hahn
2015-12-15 00:03:42 +01:00
parent ca52c56e34
commit de3e843d24
4 changed files with 8 additions and 4 deletions

View File

@@ -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) }),
}