Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
zeta: Small refactoring in license detection check - rfind instead of iterated ends_with (#37329)
Michael Sloanc01f12b15d26
diff --git a/crates/zeta/src/license_detection.rs b/crates/zeta/src/license_detection.rsindex 2939f8a0c49..5f207a44e8b 100644--- a/crates/zeta/src/license_detection.rs+++ b/crates/zeta/src/license_detection.rs@@ -202,20 +202,13 @@ fn check_pattern(pattern: &[PatternPart], input: &str) -> bool {match_any_chars.end += part.match_any_chars.end;continue;}- let mut matched = false;- for skip_count in match_any_chars.start..=match_any_chars.end {- let end_ix = input_ix.saturating_sub(skip_count);- if end_ix < part.text.len() {- break;- }- if input[..end_ix].ends_with(&part.text) {- matched = true;- input_ix = end_ix - part.text.len();- match_any_chars = part.match_any_chars.clone();- break;- }- }- if !matched && !part.optional {+ let search_range_start = input_ix.saturating_sub(match_any_chars.end + part.text.len());+ let search_range_end = input_ix.saturating_sub(match_any_chars.start);+ let found_ix = &input[search_range_start..search_range_end].rfind(&part.text);+ if let Some(found_ix) = found_ix {+ input_ix = search_range_start + found_ix;+ match_any_chars = part.match_any_chars.clone();+ } else if !part.optional {log::trace!("Failed to match pattern `...{}` against input `...{}`",&part.text[part.text.len().saturating_sub(128)..],