about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/std/src/io/buffered/linewritershim.rs2
-rw-r--r--library/std/src/io/mod.rs2
-rw-r--r--library/std/src/sys/pal/hermit/memchr.rs1
-rw-r--r--library/std/src/sys/pal/hermit/mod.rs1
-rw-r--r--library/std/src/sys/pal/hermit/os.rs2
-rw-r--r--library/std/src/sys/pal/sgx/memchr.rs1
-rw-r--r--library/std/src/sys/pal/sgx/mod.rs1
-rw-r--r--library/std/src/sys/pal/solid/memchr.rs21
-rw-r--r--library/std/src/sys/pal/solid/mod.rs1
-rw-r--r--library/std/src/sys/pal/solid/os.rs4
-rw-r--r--library/std/src/sys/pal/teeos/mod.rs2
-rw-r--r--library/std/src/sys/pal/uefi/mod.rs4
-rw-r--r--library/std/src/sys/pal/unix/memchr.rs40
-rw-r--r--library/std/src/sys/pal/unix/mod.rs1
-rw-r--r--library/std/src/sys/pal/unix/os.rs2
-rw-r--r--library/std/src/sys/pal/unsupported/common.rs4
-rw-r--r--library/std/src/sys/pal/wasi/os.rs2
-rw-r--r--library/std/src/sys/pal/windows/memchr.rs5
-rw-r--r--library/std/src/sys/pal/windows/mod.rs1
-rw-r--r--library/std/src/sys/pal/zkvm/mod.rs4
-rw-r--r--library/std/src/sys_common/memchr.rs51
-rw-r--r--library/std/src/sys_common/memchr/tests.rs86
-rw-r--r--library/std/src/sys_common/mod.rs1
23 files changed, 8 insertions, 231 deletions
diff --git a/library/std/src/io/buffered/linewritershim.rs b/library/std/src/io/buffered/linewritershim.rs
index f2a55da05b2..7eadfd41366 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 102db62fced..f35bffd6a3c 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/pal/hermit/memchr.rs b/library/std/src/sys/pal/hermit/memchr.rs
deleted file mode 100644
index 9967482197e..00000000000
--- a/library/std/src/sys/pal/hermit/memchr.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub use core::slice::memchr::{memchr, memrchr};
diff --git a/library/std/src/sys/pal/hermit/mod.rs b/library/std/src/sys/pal/hermit/mod.rs
index ada408107dc..910935541bd 100644
--- a/library/std/src/sys/pal/hermit/mod.rs
+++ b/library/std/src/sys/pal/hermit/mod.rs
@@ -25,7 +25,6 @@ pub mod fs;
 pub mod futex;
 #[path = "../unsupported/io.rs"]
 pub mod io;
-pub mod memchr;
 pub mod net;
 pub mod os;
 #[path = "../unsupported/pipe.rs"]
diff --git a/library/std/src/sys/pal/hermit/os.rs b/library/std/src/sys/pal/hermit/os.rs
index a54536aecb8..c26c275f931 100644
--- a/library/std/src/sys/pal/hermit/os.rs
+++ b/library/std/src/sys/pal/hermit/os.rs
@@ -9,9 +9,9 @@ use crate::os::hermit::ffi::OsStringExt;
 use crate::path::{self, PathBuf};
 use crate::str;
 use crate::sync::Mutex;
-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/pal/sgx/memchr.rs b/library/std/src/sys/pal/sgx/memchr.rs
deleted file mode 100644
index 9967482197e..00000000000
--- a/library/std/src/sys/pal/sgx/memchr.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub use core::slice::memchr::{memchr, memrchr};
diff --git a/library/std/src/sys/pal/sgx/mod.rs b/library/std/src/sys/pal/sgx/mod.rs
index 8ef3495884f..76f930b86f2 100644
--- a/library/std/src/sys/pal/sgx/mod.rs
+++ b/library/std/src/sys/pal/sgx/mod.rs
@@ -17,7 +17,6 @@ pub mod fd;
 pub mod fs;
 #[path = "../unsupported/io.rs"]
 pub mod io;
-pub mod memchr;
 pub mod net;
 pub mod os;
 #[path = "../unsupported/pipe.rs"]
diff --git a/library/std/src/sys/pal/solid/memchr.rs b/library/std/src/sys/pal/solid/memchr.rs
deleted file mode 100644
index 452b7a3de1b..00000000000
--- a/library/std/src/sys/pal/solid/memchr.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
-    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<usize> {
-    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/pal/solid/mod.rs b/library/std/src/sys/pal/solid/mod.rs
index 9ada7d130f0..109ee1a0ab6 100644
--- a/library/std/src/sys/pal/solid/mod.rs
+++ b/library/std/src/sys/pal/solid/mod.rs
@@ -33,7 +33,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/pal/solid/os.rs b/library/std/src/sys/pal/solid/os.rs
index 5ceab3b27e0..ef35d8788a2 100644
--- a/library/std/src/sys/pal/solid/os.rs
+++ b/library/std/src/sys/pal/solid/os.rs
@@ -12,7 +12,9 @@ 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/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs
index 51ef96a69a0..1fb9d5438de 100644
--- a/library/std/src/sys/pal/teeos/mod.rs
+++ b/library/std/src/sys/pal/teeos/mod.rs
@@ -18,8 +18,6 @@ pub mod env;
 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;
diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs
index ff8e3bd32ad..7c5b37fb490 100644
--- a/library/std/src/sys/pal/uefi/mod.rs
+++ b/library/std/src/sys/pal/uefi/mod.rs
@@ -48,10 +48,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<crate::ffi::c_void> =
     AtomicPtr::new(crate::ptr::null_mut());
 
diff --git a/library/std/src/sys/pal/unix/memchr.rs b/library/std/src/sys/pal/unix/memchr.rs
deleted file mode 100644
index 73ba604eccb..00000000000
--- a/library/std/src/sys/pal/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<usize> {
-    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<usize> {
-    #[cfg(target_os = "linux")]
-    fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option<usize> {
-        // 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<usize> {
-        core::slice::memchr::memrchr(needle, haystack)
-    }
-
-    memrchr_specific(needle, haystack)
-}
diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs
index 04b8c5ca916..aac3315f645 100644
--- a/library/std/src/sys/pal/unix/mod.rs
+++ b/library/std/src/sys/pal/unix/mod.rs
@@ -20,7 +20,6 @@ pub mod io;
 pub mod kernel_copy;
 #[cfg(target_os = "l4re")]
 mod l4re;
-pub mod memchr;
 #[cfg(not(target_os = "l4re"))]
 pub mod net;
 #[cfg(target_os = "l4re")]
diff --git a/library/std/src/sys/pal/unix/os.rs b/library/std/src/sys/pal/unix/os.rs
index af2b9db4685..0b9c8027e6f 100644
--- a/library/std/src/sys/pal/unix/os.rs
+++ b/library/std/src/sys/pal/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/pal/unsupported/common.rs b/library/std/src/sys/pal/unsupported/common.rs
index 5c379992b20..4f44db610af 100644
--- a/library/std/src/sys/pal/unsupported/common.rs
+++ b/library/std/src/sys/pal/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/pal/wasi/os.rs b/library/std/src/sys/pal/wasi/os.rs
index d62ff8a2f18..ee377b6ef79 100644
--- a/library/std/src/sys/pal/wasi/os.rs
+++ b/library/std/src/sys/pal/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/pal/windows/memchr.rs b/library/std/src/sys/pal/windows/memchr.rs
deleted file mode 100644
index b9e5bcc1b4b..00000000000
--- a/library/std/src/sys/pal/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/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index b47d213df34..831cb04c566 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -19,7 +19,6 @@ pub mod env;
 pub mod fs;
 pub mod handle;
 pub mod io;
-pub mod memchr;
 pub mod net;
 pub mod os;
 pub mod pipe;
diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs
index 016c977dc33..6c714f76309 100644
--- a/library/std/src/sys/pal/zkvm/mod.rs
+++ b/library/std/src/sys/pal/zkvm/mod.rs
@@ -43,10 +43,6 @@ mod abi;
 
 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_common/memchr.rs b/library/std/src/sys_common/memchr.rs
deleted file mode 100644
index b219e878912..00000000000
--- 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<usize> {
-    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<usize> {
-    sys::memrchr(needle, haystack)
-}
diff --git a/library/std/src/sys_common/memchr/tests.rs b/library/std/src/sys_common/memchr/tests.rs
deleted file mode 100644
index 557d749c7f6..00000000000
--- a/library/std/src/sys_common/memchr/tests.rs
+++ /dev/null
@@ -1,86 +0,0 @@
-// Original implementation taken from rust-memchr.
-// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
-
-// test the implementations for the current platform
-use super::{memchr, memrchr};
-
-#[test]
-fn matches_one() {
-    assert_eq!(Some(0), memchr(b'a', b"a"));
-}
-
-#[test]
-fn matches_begin() {
-    assert_eq!(Some(0), memchr(b'a', b"aaaa"));
-}
-
-#[test]
-fn matches_end() {
-    assert_eq!(Some(4), memchr(b'z', b"aaaaz"));
-}
-
-#[test]
-fn matches_nul() {
-    assert_eq!(Some(4), memchr(b'\x00', b"aaaa\x00"));
-}
-
-#[test]
-fn matches_past_nul() {
-    assert_eq!(Some(5), memchr(b'z', b"aaaa\x00z"));
-}
-
-#[test]
-fn no_match_empty() {
-    assert_eq!(None, memchr(b'a', b""));
-}
-
-#[test]
-fn no_match() {
-    assert_eq!(None, memchr(b'a', b"xyz"));
-}
-
-#[test]
-fn matches_one_reversed() {
-    assert_eq!(Some(0), memrchr(b'a', b"a"));
-}
-
-#[test]
-fn matches_begin_reversed() {
-    assert_eq!(Some(3), memrchr(b'a', b"aaaa"));
-}
-
-#[test]
-fn matches_end_reversed() {
-    assert_eq!(Some(0), memrchr(b'z', b"zaaaa"));
-}
-
-#[test]
-fn matches_nul_reversed() {
-    assert_eq!(Some(4), memrchr(b'\x00', b"aaaa\x00"));
-}
-
-#[test]
-fn matches_past_nul_reversed() {
-    assert_eq!(Some(0), memrchr(b'z', b"z\x00aaaa"));
-}
-
-#[test]
-fn no_match_empty_reversed() {
-    assert_eq!(None, memrchr(b'a', b""));
-}
-
-#[test]
-fn no_match_reversed() {
-    assert_eq!(None, memrchr(b'a', b"xyz"));
-}
-
-#[test]
-fn each_alignment() {
-    let mut data = [1u8; 64];
-    let needle = 2;
-    let pos = 40;
-    data[pos] = needle;
-    for start in 0..16 {
-        assert_eq!(Some(pos - start), memchr(needle, &data[start..]));
-    }
-}
diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs
index 01f83ecb414..c9025a81bf3 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;