diff --git a/library/std/src/io/buffered/linewritershim.rs b/library/std/src/io/buffered/linewritershim.rs index f2a55da05b22e..7eadfd413661d 100644 --- a/library/std/src/io/buffered/linewritershim.rs +++ b/library/std/src/io/buffered/linewritershim.rs @@ -1,5 +1,5 @@ use crate::io::{self, BufWriter, IoSlice, Write}; -use crate::sys_common::memchr; +use core::slice::memchr; /// Private helper struct for implementing the line-buffered writing logic. /// This shim temporarily wraps a BufWriter, and uses its internals to diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index e3aa973741f1f..401f19cb47909 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -304,7 +304,7 @@ use crate::ops::{Deref, DerefMut}; use crate::slice; use crate::str; use crate::sys; -use crate::sys_common::memchr; +use core::slice::memchr; #[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub use self::buffered::WriterPanicked; diff --git a/library/std/src/sys/hermit/memchr.rs b/library/std/src/sys/hermit/memchr.rs deleted file mode 100644 index 9967482197eb3..0000000000000 --- a/library/std/src/sys/hermit/memchr.rs +++ /dev/null @@ -1 +0,0 @@ -pub use core::slice::memchr::{memchr, memrchr}; diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index abd7eb353f814..4c4b5cdf0823b 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -27,7 +27,6 @@ pub mod fs; pub mod futex; #[path = "../unsupported/io.rs"] pub mod io; -pub mod memchr; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] diff --git a/library/std/src/sys/hermit/os.rs b/library/std/src/sys/hermit/os.rs index c79197a9ad1fa..89cadfc9197bc 100644 --- a/library/std/src/sys/hermit/os.rs +++ b/library/std/src/sys/hermit/os.rs @@ -9,9 +9,9 @@ use crate::path::{self, PathBuf}; use crate::str; use crate::sync::Mutex; use crate::sys::hermit::abi; -use crate::sys::memchr; use crate::sys::unsupported; use crate::vec; +use core::slice::memchr; pub fn errno() -> i32 { 0 diff --git a/library/std/src/sys/sgx/memchr.rs b/library/std/src/sys/sgx/memchr.rs deleted file mode 100644 index 9967482197eb3..0000000000000 --- a/library/std/src/sys/sgx/memchr.rs +++ /dev/null @@ -1 +0,0 @@ -pub use core::slice::memchr::{memchr, memrchr}; diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs index 09d3f7638ca2d..92a8670df6228 100644 --- a/library/std/src/sys/sgx/mod.rs +++ b/library/std/src/sys/sgx/mod.rs @@ -21,7 +21,6 @@ pub mod fd; pub mod fs; #[path = "../unsupported/io.rs"] pub mod io; -pub mod memchr; pub mod net; pub mod os; #[path = "../unix/os_str.rs"] diff --git a/library/std/src/sys/solid/memchr.rs b/library/std/src/sys/solid/memchr.rs deleted file mode 100644 index 452b7a3de1b33..0000000000000 --- a/library/std/src/sys/solid/memchr.rs +++ /dev/null @@ -1,21 +0,0 @@ -pub fn memchr(needle: u8, haystack: &[u8]) -> Option { - let p = unsafe { - libc::memchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len(), - ) - }; - if p.is_null() { None } else { Some(p as usize - (haystack.as_ptr() as usize)) } -} - -pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { - let p = unsafe { - libc::memrchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len(), - ) - }; - if p.is_null() { None } else { Some(p as usize - (haystack.as_ptr() as usize)) } -} diff --git a/library/std/src/sys/solid/mod.rs b/library/std/src/sys/solid/mod.rs index 5af83653cf849..a11a624dc4427 100644 --- a/library/std/src/sys/solid/mod.rs +++ b/library/std/src/sys/solid/mod.rs @@ -40,7 +40,6 @@ pub mod pipe; pub mod process; pub mod stdio; pub use self::itron::thread; -pub mod memchr; pub mod thread_local_dtor; pub mod thread_local_key; pub use self::itron::thread_parking; diff --git a/library/std/src/sys/solid/os.rs b/library/std/src/sys/solid/os.rs index ff81544ba9151..c9e805cf8d188 100644 --- a/library/std/src/sys/solid/os.rs +++ b/library/std/src/sys/solid/os.rs @@ -12,7 +12,8 @@ use crate::sync::{PoisonError, RwLock}; use crate::sys::common::small_c_string::run_with_cstr; use crate::vec; -use super::{error, itron, memchr}; +use super::{error, itron}; +use core::slice::memchr; // `solid` directly maps `errno`s to μITRON error codes. impl itron::error::ItronError { diff --git a/library/std/src/sys/teeos/mod.rs b/library/std/src/sys/teeos/mod.rs index ed8c54b2c36fb..58813cc052fd7 100644 --- a/library/std/src/sys/teeos/mod.rs +++ b/library/std/src/sys/teeos/mod.rs @@ -21,8 +21,6 @@ pub mod locks; pub mod fs; #[path = "../unsupported/io.rs"] pub mod io; -#[path = "../unix/memchr.rs"] -pub mod memchr; pub mod net; #[path = "../unsupported/once.rs"] pub mod once; @@ -49,6 +47,8 @@ pub mod time; use crate::io::ErrorKind; +use core::slice::memchr; + pub fn abort_internal() -> ! { unsafe { libc::abort() } } diff --git a/library/std/src/sys/uefi/mod.rs b/library/std/src/sys/uefi/mod.rs index 4edc00e3ea022..7d84882f2fb62 100644 --- a/library/std/src/sys/uefi/mod.rs +++ b/library/std/src/sys/uefi/mod.rs @@ -57,10 +57,6 @@ use crate::os::uefi; use crate::ptr::NonNull; use crate::sync::atomic::{AtomicPtr, Ordering}; -pub mod memchr { - pub use core::slice::memchr::{memchr, memrchr}; -} - static EXIT_BOOT_SERVICE_EVENT: AtomicPtr = AtomicPtr::new(crate::ptr::null_mut()); diff --git a/library/std/src/sys/unix/memchr.rs b/library/std/src/sys/unix/memchr.rs deleted file mode 100644 index 73ba604eccba2..0000000000000 --- a/library/std/src/sys/unix/memchr.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Original implementation taken from rust-memchr. -// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch - -pub fn memchr(needle: u8, haystack: &[u8]) -> Option { - let p = unsafe { - libc::memchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len(), - ) - }; - if p.is_null() { None } else { Some(p.addr() - haystack.as_ptr().addr()) } -} - -pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { - #[cfg(target_os = "linux")] - fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { - // GNU's memrchr() will - unlike memchr() - error if haystack is empty. - if haystack.is_empty() { - return None; - } - let p = unsafe { - libc::memrchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len(), - ) - }; - // FIXME: this should *likely* use `offset_from`, but more - // investigation is needed (including running tests in miri). - if p.is_null() { None } else { Some(p.addr() - haystack.as_ptr().addr()) } - } - - #[cfg(not(target_os = "linux"))] - fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { - core::slice::memchr::memrchr(needle, haystack) - } - - memrchr_specific(needle, haystack) -} diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index b5da5f870ec12..c148445a84446 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -23,7 +23,6 @@ pub mod kernel_copy; #[cfg(target_os = "l4re")] mod l4re; pub mod locks; -pub mod memchr; #[cfg(not(target_os = "l4re"))] pub mod net; #[cfg(target_os = "l4re")] diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 881b3a25c5152..e877a9c40ec70 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -21,8 +21,8 @@ use crate::sync::{PoisonError, RwLock}; use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr}; use crate::sys::cvt; use crate::sys::fd; -use crate::sys::memchr; use crate::vec; +use core::slice::memchr; #[cfg(all(target_env = "gnu", not(target_os = "vxworks")))] use crate::sys::weak::weak; diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs index 5c379992b2041..4f44db610af15 100644 --- a/library/std/src/sys/unsupported/common.rs +++ b/library/std/src/sys/unsupported/common.rs @@ -1,9 +1,5 @@ use crate::io as std_io; -pub mod memchr { - pub use core::slice::memchr::{memchr, memrchr}; -} - // SAFETY: must be called only once during runtime initialization. // NOTE: this is not guaranteed to run, for example when Rust code is called externally. pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {} diff --git a/library/std/src/sys/wasi/os.rs b/library/std/src/sys/wasi/os.rs index d53bddd8e9dfe..c5f09bac33d16 100644 --- a/library/std/src/sys/wasi/os.rs +++ b/library/std/src/sys/wasi/os.rs @@ -10,9 +10,9 @@ use crate::os::wasi::prelude::*; use crate::path::{self, PathBuf}; use crate::str; use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr}; -use crate::sys::memchr; use crate::sys::unsupported; use crate::vec; +use core::slice::memchr; // Add a few symbols not in upstream `libc` just yet. mod libc { diff --git a/library/std/src/sys/windows/memchr.rs b/library/std/src/sys/windows/memchr.rs deleted file mode 100644 index b9e5bcc1b4bbd..0000000000000 --- a/library/std/src/sys/windows/memchr.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Original implementation taken from rust-memchr. -// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch - -// Fallback memchr is fastest on Windows. -pub use core::slice::memchr::{memchr, memrchr}; diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 8b722f01a5d30..ffbfcb14ce5a6 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -21,7 +21,6 @@ pub mod fs; pub mod handle; pub mod io; pub mod locks; -pub mod memchr; pub mod net; pub mod os; pub mod os_str; diff --git a/library/std/src/sys_common/memchr.rs b/library/std/src/sys_common/memchr.rs deleted file mode 100644 index b219e87891264..0000000000000 --- a/library/std/src/sys_common/memchr.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Original implementation taken from rust-memchr. -// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch - -use crate::sys::memchr as sys; - -#[cfg(test)] -mod tests; - -/// A safe interface to `memchr`. -/// -/// Returns the index corresponding to the first occurrence of `needle` in -/// `haystack`, or `None` if one is not found. -/// -/// memchr reduces to super-optimized machine code at around an order of -/// magnitude faster than `haystack.iter().position(|&b| b == needle)`. -/// (See benchmarks.) -/// -/// # Examples -/// -/// This shows how to find the first position of a byte in a byte string. -/// -/// ```ignore (cannot-doctest-private-modules) -/// use memchr::memchr; -/// -/// let haystack = b"the quick brown fox"; -/// assert_eq!(memchr(b'k', haystack), Some(8)); -/// ``` -#[inline] -pub fn memchr(needle: u8, haystack: &[u8]) -> Option { - sys::memchr(needle, haystack) -} - -/// A safe interface to `memrchr`. -/// -/// Returns the index corresponding to the last occurrence of `needle` in -/// `haystack`, or `None` if one is not found. -/// -/// # Examples -/// -/// This shows how to find the last position of a byte in a byte string. -/// -/// ```ignore (cannot-doctest-private-modules) -/// use memchr::memrchr; -/// -/// let haystack = b"the quick brown fox"; -/// assert_eq!(memrchr(b'o', haystack), Some(17)); -/// ``` -#[inline] -pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { - sys::memrchr(needle, haystack) -} diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 851832a377cf8..ffe116c9f7aa0 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -24,7 +24,6 @@ pub mod backtrace; pub mod fs; pub mod io; pub mod lazy_box; -pub mod memchr; pub mod once; pub mod process; pub mod thread;