Skip to content

Commit 8cda8df

Browse files
committed
memchr hack
1 parent 76dbe29 commit 8cda8df

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/core/src/slice/memchr.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
8383
let mut offset = ptr.align_offset(USIZE_BYTES);
8484

8585
if offset > 0 {
86-
offset = cmp::min(offset, len);
87-
if let Some(index) = memchr_naive(x, &text[..offset]) {
86+
// FIXME(const-hack, fee1-dead): replace with min
87+
offset = if offset < len { offset } else { len };
88+
// FIXME(const-hack, fee1-dead): replace with range slicing
89+
let slice = unsafe { super::from_raw_parts(text.as_ptr(), offset) };
90+
if let Some(index) = memchr_naive(x, slice) {
8891
return Some(index);
8992
}
9093
}
@@ -110,7 +113,9 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
110113

111114
// Find the byte after the point the body loop stopped.
112115
// FIXME(const-hack): Use `?` instead.
113-
if let Some(i) = memchr_naive(x, &text[offset..]) { Some(offset + i) } else { None }
116+
// FIXME(const-hack, fee1-dead): use range slicing
117+
let slice = unsafe { super::from_raw_parts(text.as_ptr().add(offset), text.len() - offset) };
118+
if let Some(i) = memchr_naive(x, slice) { Some(offset + i) } else { None }
114119
}
115120

116121
/// Returns the last index matching the byte `x` in `text`.

0 commit comments

Comments
 (0)