]> git.lizzy.rs Git - rust.git/commitdiff
Use memchr for [i8]::contains as well
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 18 Dec 2017 18:22:53 +0000 (10:22 -0800)
committerManish Goregaokar <manishsmail@gmail.com>
Sun, 31 Dec 2017 15:05:39 +0000 (20:35 +0530)
src/libcore/slice/mod.rs

index 346ee27331121630a6a78431e2aeedad1f38a530..7b08ec131029cfacd22430e562915aeeb8014840 100644 (file)
@@ -2635,3 +2635,11 @@ fn slice_contains(&self, x: &[Self]) -> bool {
         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()
+    }
+}