From 5e98788947b28da3da27f4e156b877eb0cb1593e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20ROUDNINSKI?= Date: Tue, 5 Jul 2022 19:31:23 +0200 Subject: [PATCH] perf: use is_match_at instead of shortest_match_at Local benchmarks show up to 15% reduction in terms of number of retired instructions executed and at least 5% reduction in terms of CPU time. This is basically a bit of a manual inlining here, instead of doing more redirection. PR #788 --- src/re_bytes.rs | 2 +- src/re_unicode.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/re_bytes.rs b/src/re_bytes.rs index ae55d6d..7f372eb 100644 --- a/src/re_bytes.rs +++ b/src/re_bytes.rs @@ -578,7 +578,7 @@ impl Regex { /// context into consideration. For example, the `\A` anchor can only /// match when `start == 0`. pub fn is_match_at(&self, text: &[u8], start: usize) -> bool { - self.shortest_match_at(text, start).is_some() + self.0.searcher().is_match_at(text, start) } /// Returns the same as find, but starts the search at the given diff --git a/src/re_unicode.rs b/src/re_unicode.rs index 8c4ecfc..46e70f2 100644 --- a/src/re_unicode.rs +++ b/src/re_unicode.rs @@ -636,7 +636,7 @@ impl Regex { /// context into consideration. For example, the `\A` anchor can only /// match when `start == 0`. pub fn is_match_at(&self, text: &str, start: usize) -> bool { - self.shortest_match_at(text, start).is_some() + self.0.searcher_str().is_match_at(text, start) } /// Returns the same as find, but starts the search at the given