1c67d6573Sopenharmony_ci/// Searches for the given needle in the given haystack. 2c67d6573Sopenharmony_ci/// 3c67d6573Sopenharmony_ci/// If the perf-literal feature is enabled, then this uses the super optimized 4c67d6573Sopenharmony_ci/// memchr crate. Otherwise, it uses the naive byte-at-a-time implementation. 5c67d6573Sopenharmony_cipub fn find_byte(needle: u8, haystack: &[u8]) -> Option<usize> { 6c67d6573Sopenharmony_ci #[cfg(not(feature = "perf-literal"))] 7c67d6573Sopenharmony_ci fn imp(needle: u8, haystack: &[u8]) -> Option<usize> { 8c67d6573Sopenharmony_ci haystack.iter().position(|&b| b == needle) 9c67d6573Sopenharmony_ci } 10c67d6573Sopenharmony_ci 11c67d6573Sopenharmony_ci #[cfg(feature = "perf-literal")] 12c67d6573Sopenharmony_ci fn imp(needle: u8, haystack: &[u8]) -> Option<usize> { 13c67d6573Sopenharmony_ci use memchr::memchr; 14c67d6573Sopenharmony_ci memchr(needle, haystack) 15c67d6573Sopenharmony_ci } 16c67d6573Sopenharmony_ci 17c67d6573Sopenharmony_ci imp(needle, haystack) 18c67d6573Sopenharmony_ci} 19