##// END OF EJS Templates
rust-matchers: raw regular expression builder...
Georges Racinet -
r52364:5633de95 stable
parent child Browse files
Show More
@@ -737,14 +737,11 b' impl RegexMatcher {'
737 }
737 }
738 }
738 }
739
739
740 /// Returns a function that matches an `HgPath` against the given regex
740 /// Return a `RegexBuilder` from a bytes pattern
741 /// pattern.
742 ///
741 ///
743 /// This can fail when the pattern is invalid or not supported by the
742 /// This works around the fact that even if it works on byte haysacks,
744 /// underlying engine (the `regex` crate), for instance anything with
743 /// [`regex::bytes::Regex`] still uses UTF-8 patterns.
745 /// back-references.
744 pub fn re_bytes_builder(pattern: &[u8]) -> regex::bytes::RegexBuilder {
746 #[logging_timer::time("trace")]
747 fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> {
748 use std::io::Write;
745 use std::io::Write;
749
746
750 // The `regex` crate adds `.*` to the start and end of expressions if there
747 // The `regex` crate adds `.*` to the start and end of expressions if there
@@ -764,7 +761,18 b' fn re_matcher(pattern: &[u8]) -> Pattern'
764 // # Safety
761 // # Safety
765 // This is safe because we escaped all non-ASCII bytes.
762 // This is safe because we escaped all non-ASCII bytes.
766 let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) };
763 let pattern_string = unsafe { String::from_utf8_unchecked(escaped_bytes) };
767 let re = regex::bytes::RegexBuilder::new(&pattern_string)
764 regex::bytes::RegexBuilder::new(&pattern_string)
765 }
766
767 /// Returns a function that matches an `HgPath` against the given regex
768 /// pattern.
769 ///
770 /// This can fail when the pattern is invalid or not supported by the
771 /// underlying engine (the `regex` crate), for instance anything with
772 /// back-references.
773 #[logging_timer::time("trace")]
774 fn re_matcher(pattern: &[u8]) -> PatternResult<RegexMatcher> {
775 let re = re_bytes_builder(pattern)
768 .unicode(false)
776 .unicode(false)
769 // Big repos with big `.hgignore` will hit the default limit and
777 // Big repos with big `.hgignore` will hit the default limit and
770 // incur a significant performance hit. One repo's `hg status` hit
778 // incur a significant performance hit. One repo's `hg status` hit
General Comments 0
You need to be logged in to leave comments. Login now