memchr hack
This commit is contained in:
parent
76dbe29104
commit
8cda8df578
1 changed files with 8 additions and 3 deletions
|
@ -83,8 +83,11 @@ const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
|
||||||
let mut offset = ptr.align_offset(USIZE_BYTES);
|
let mut offset = ptr.align_offset(USIZE_BYTES);
|
||||||
|
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
offset = cmp::min(offset, len);
|
// FIXME(const-hack, fee1-dead): replace with min
|
||||||
if let Some(index) = memchr_naive(x, &text[..offset]) {
|
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);
|
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.
|
// Find the byte after the point the body loop stopped.
|
||||||
// FIXME(const-hack): Use `?` instead.
|
// 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`.
|
/// Returns the last index matching the byte `x` in `text`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue