xref: /aosp_15_r20/external/cronet/third_party/rust/chromium_crates_io/vendor/regex-1.10.4/src/find_byte.rs (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 /// Searches for the given needle in the given haystack.
2 ///
3 /// If the perf-literal feature is enabled, then this uses the super optimized
4 /// memchr crate. Otherwise, it uses the naive byte-at-a-time implementation.
find_byte(needle: u8, haystack: &[u8]) -> Option<usize>5 pub(crate) fn find_byte(needle: u8, haystack: &[u8]) -> Option<usize> {
6     #[cfg(not(feature = "perf-literal"))]
7     fn imp(needle: u8, haystack: &[u8]) -> Option<usize> {
8         haystack.iter().position(|&b| b == needle)
9     }
10 
11     #[cfg(feature = "perf-literal")]
12     fn imp(needle: u8, haystack: &[u8]) -> Option<usize> {
13         memchr::memchr(needle, haystack)
14     }
15 
16     imp(needle, haystack)
17 }
18