Skip to content

Commit 89c5cd7

Browse files
committed
perf: improve pattern_key_compare (#639)
1 parent 0a4705a commit 89c5cd7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,10 +2018,10 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
20182018
// 2. Assert: keyB ends with "/" or contains only a single "*".
20192019
debug_assert!(key_b.ends_with('/') || key_b.match_indices('*').count() == 1, "{key_b}");
20202020
// 3. Let baseLengthA be the index of "*" in keyA plus one, if keyA contains "*", or the length of keyA otherwise.
2021-
let a_pos = key_a.chars().position(|c| c == '*');
2021+
let a_pos = key_a.bytes().position(|c| c == b'*');
20222022
let base_length_a = a_pos.map_or(key_a.len(), |p| p + 1);
20232023
// 4. Let baseLengthB be the index of "*" in keyB plus one, if keyB contains "*", or the length of keyB otherwise.
2024-
let b_pos = key_b.chars().position(|c| c == '*');
2024+
let b_pos = key_b.bytes().position(|c| c == b'*');
20252025
let base_length_b = b_pos.map_or(key_b.len(), |p| p + 1);
20262026
// 5. If baseLengthA is greater than baseLengthB, return -1.
20272027
if base_length_a > base_length_b {
@@ -2032,11 +2032,11 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
20322032
return Ordering::Greater;
20332033
}
20342034
// 7. If keyA does not contain "*", return 1.
2035-
if !key_a.contains('*') {
2035+
if a_pos.is_none() {
20362036
return Ordering::Greater;
20372037
}
20382038
// 8. If keyB does not contain "*", return -1.
2039-
if !key_b.contains('*') {
2039+
if b_pos.is_none() {
20402040
return Ordering::Less;
20412041
}
20422042
// 9. If the length of keyA is greater than the length of keyB, return -1.

0 commit comments

Comments
 (0)