about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/slice/memchr.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/library/core/src/slice/memchr.rs b/library/core/src/slice/memchr.rs
index 98c8349eb60..8ceca7f9185 100644
--- a/library/core/src/slice/memchr.rs
+++ b/library/core/src/slice/memchr.rs
@@ -83,8 +83,11 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
     let mut offset = ptr.align_offset(USIZE_BYTES);
 
     if offset > 0 {
-        offset = cmp::min(offset, len);
-        if let Some(index) = memchr_naive(x, &text[..offset]) {
+        // FIXME(const-hack, fee1-dead): replace with min
+        offset = if offset < len { offset } else { len };
+        // FIXME(const-hack, fee1-dead): replace with range slicing
+        let slice = unsafe { super::from_raw_parts(text.as_ptr(), offset) };
+        if let Some(index) = memchr_naive(x, slice) {
             return Some(index);
         }
     }
@@ -110,7 +113,9 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
 
     // Find the byte after the point the body loop stopped.
     // FIXME(const-hack): Use `?` instead.
-    if let Some(i) = memchr_naive(x, &text[offset..]) { Some(offset + i) } else { None }
+    // FIXME(const-hack, fee1-dead): use range slicing
+    let slice = unsafe { super::from_raw_parts(text.as_ptr().add(offset), text.len() - offset) };
+    if let Some(i) = memchr_naive(x, slice) { Some(offset + i) } else { None }
 }
 
 /// Returns the last index matching the byte `x` in `text`.