Skip to content

Commit

Permalink
Use memchr for [i8]::contains as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Dec 31, 2017
1 parent 1d818a4 commit 4ef6847
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2635,3 +2635,11 @@ impl SliceContains for u8 {
memchr::memchr(*self, x).is_some()
}
}

impl SliceContains for i8 {
fn slice_contains(&self, x: &[Self]) -> bool {
let byte = *self as u8;
let bytes: &[u8] = unsafe { from_raw_parts(x.as_ptr() as *const u8, x.len()) };
memchr::memchr(byte, bytes).is_some()
}
}

0 comments on commit 4ef6847

Please sign in to comment.