diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
commit | 4f9fe856a25ab29345b90e7725509e9ee38a37be (patch) | |
tree | e4ffd8a9374cae7b21f7cbfb352927e0e074aff6 /vendor/dissimilar/src/find.rs | |
parent | Adding upstream version 1.68.2+dfsg1. (diff) | |
download | rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.tar.xz rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.zip |
Adding upstream version 1.69.0+dfsg1.upstream/1.69.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/dissimilar/src/find.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/vendor/dissimilar/src/find.rs b/vendor/dissimilar/src/find.rs index 90ca2c6c5..4af3b8bee 100644 --- a/vendor/dissimilar/src/find.rs +++ b/vendor/dissimilar/src/find.rs @@ -1,5 +1,5 @@ // The strstr implementation in this file is extracted from the Rust standard -// library's str::find. The algorithm works for arbitrary &[u8] haystack and +// library's str::find. The algorithm works for arbitrary &[T] haystack and // needle but is only exposed by the standard library on UTF-8 strings. // // https://github.com/rust-lang/rust/blob/1.40.0/src/libcore/str/pattern.rs @@ -80,7 +80,7 @@ use std::cmp; use std::usize; -pub fn find(haystack: &[u8], needle: &[u8]) -> Option<usize> { +pub fn find(haystack: &[char], needle: &[char]) -> Option<usize> { assert!(!needle.is_empty()); // crit_pos: critical factorization index @@ -177,12 +177,12 @@ pub fn find(haystack: &[u8], needle: &[u8]) -> Option<usize> { } } -fn byteset_create(bytes: &[u8]) -> u64 { - bytes.iter().fold(0, |a, &b| (1 << (b & 0x3f)) | a) +fn byteset_create(chars: &[char]) -> u64 { + chars.iter().fold(0, |a, &ch| (1 << (ch as u8 & 0x3f)) | a) } -fn byteset_contains(byteset: u64, byte: u8) -> bool { - (byteset >> ((byte & 0x3f) as usize)) & 1 != 0 +fn byteset_contains(byteset: u64, ch: char) -> bool { + (byteset >> ((ch as u8 & 0x3f) as usize)) & 1 != 0 } // Compute the maximal suffix of `arr`. @@ -197,7 +197,7 @@ fn byteset_contains(byteset: u64, byte: u8) -> bool { // a critical factorization. // // For long period cases, the resulting period is not exact (it is too short). -fn maximal_suffix(arr: &[u8], order_greater: bool) -> (usize, usize) { +fn maximal_suffix(arr: &[char], order_greater: bool) -> (usize, usize) { let mut left = 0; // Corresponds to i in the paper let mut right = 1; // Corresponds to j in the paper let mut offset = 0; // Corresponds to k in the paper, but starting at 0 |