diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:32 +0000 |
commit | 4547b622d8d29df964fa2914213088b148c498fc (patch) | |
tree | 9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/bstr/src/byteset/mod.rs | |
parent | Releasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz rustc-4547b622d8d29df964fa2914213088b148c498fc.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bstr/src/byteset/mod.rs')
-rw-r--r-- | vendor/bstr/src/byteset/mod.rs | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/vendor/bstr/src/byteset/mod.rs b/vendor/bstr/src/byteset/mod.rs deleted file mode 100644 index 043d30986..000000000 --- a/vendor/bstr/src/byteset/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use memchr::{memchr, memchr2, memchr3, memrchr, memrchr2, memrchr3}; -mod scalar; - -#[inline] -fn build_table(byteset: &[u8]) -> [u8; 256] { - let mut table = [0u8; 256]; - for &b in byteset { - table[b as usize] = 1; - } - table -} - -#[inline] -pub(crate) fn find(haystack: &[u8], byteset: &[u8]) -> Option<usize> { - match byteset.len() { - 0 => return None, - 1 => memchr(byteset[0], haystack), - 2 => memchr2(byteset[0], byteset[1], haystack), - 3 => memchr3(byteset[0], byteset[1], byteset[2], haystack), - _ => { - let table = build_table(byteset); - scalar::forward_search_bytes(haystack, |b| table[b as usize] != 0) - } - } -} - -#[inline] -pub(crate) fn rfind(haystack: &[u8], byteset: &[u8]) -> Option<usize> { - match byteset.len() { - 0 => return None, - 1 => memrchr(byteset[0], haystack), - 2 => memrchr2(byteset[0], byteset[1], haystack), - 3 => memrchr3(byteset[0], byteset[1], byteset[2], haystack), - _ => { - let table = build_table(byteset); - scalar::reverse_search_bytes(haystack, |b| table[b as usize] != 0) - } - } -} - -#[inline] -pub(crate) fn find_not(haystack: &[u8], byteset: &[u8]) -> Option<usize> { - if haystack.is_empty() { - return None; - } - match byteset.len() { - 0 => return Some(0), - 1 => scalar::inv_memchr(byteset[0], haystack), - 2 => scalar::forward_search_bytes(haystack, |b| { - b != byteset[0] && b != byteset[1] - }), - 3 => scalar::forward_search_bytes(haystack, |b| { - b != byteset[0] && b != byteset[1] && b != byteset[2] - }), - _ => { - let table = build_table(byteset); - scalar::forward_search_bytes(haystack, |b| table[b as usize] == 0) - } - } -} -#[inline] -pub(crate) fn rfind_not(haystack: &[u8], byteset: &[u8]) -> Option<usize> { - if haystack.is_empty() { - return None; - } - match byteset.len() { - 0 => return Some(haystack.len() - 1), - 1 => scalar::inv_memrchr(byteset[0], haystack), - 2 => scalar::reverse_search_bytes(haystack, |b| { - b != byteset[0] && b != byteset[1] - }), - 3 => scalar::reverse_search_bytes(haystack, |b| { - b != byteset[0] && b != byteset[1] && b != byteset[2] - }), - _ => { - let table = build_table(byteset); - scalar::reverse_search_bytes(haystack, |b| table[b as usize] == 0) - } - } -} - -#[cfg(test)] -mod tests { - quickcheck::quickcheck! { - fn qc_byteset_forward_matches_naive( - haystack: Vec<u8>, - needles: Vec<u8> - ) -> bool { - super::find(&haystack, &needles) - == haystack.iter().position(|b| needles.contains(b)) - } - fn qc_byteset_backwards_matches_naive( - haystack: Vec<u8>, - needles: Vec<u8> - ) -> bool { - super::rfind(&haystack, &needles) - == haystack.iter().rposition(|b| needles.contains(b)) - } - fn qc_byteset_forward_not_matches_naive( - haystack: Vec<u8>, - needles: Vec<u8> - ) -> bool { - super::find_not(&haystack, &needles) - == haystack.iter().position(|b| !needles.contains(b)) - } - fn qc_byteset_backwards_not_matches_naive( - haystack: Vec<u8>, - needles: Vec<u8> - ) -> bool { - super::rfind_not(&haystack, &needles) - == haystack.iter().rposition(|b| !needles.contains(b)) - } - } -} |