History

Only run regex based searches if a substring search won't do (#427)

Sebastian Thiel committed 4 years ago

Commit 295bf9f1 parent b8382022 files · +16 −4Browse files

Unified · Split

2 files
  1. git-repository/src/revision/spec/parse/delegate.rs +11 −4
  2. git-repository/src/revision/walk.rs +5 −0
git-repository/src/revision/spec/parse/delegate.rs+11−4
@@ -375,15 +375,22 @@ impl<'repo> delegate::Navigate for Delegate<'repo> { · 374 unmodified lines
375 #[cfg(not(feature = "regex"))]375 #[cfg(not(feature = "regex"))]
376 let matches = |message: &BStr| -> bool { message.contains_str(regex) };376 let matches = |message: &BStr| -> bool { message.contains_str(regex) };
377 #[cfg(feature = "regex")]377 #[cfg(feature = "regex")]
378 let compiled_regex = match regex::bytes::Regex::new(regex.to_str_lossy().as_ref()) {378 let matches = match regex::bytes::Regex::new(regex.to_str_lossy().as_ref()) {
379 Ok(regex) => regex,379 Ok(compiled) => {
380 let needs_regex = regex::escape(compiled.as_str()) != regex;
381 move |message: &BStr| -> bool {
382 if needs_regex {
383 compiled.is_match(message)
384 } else {
385 message.contains_str(regex)
386 }
387 }
388 }
380 Err(err) => {389 Err(err) => {
381 self.err.push(err.into());390 self.err.push(err.into());
382 return None;391 return None;
383 }392 }
384 };393 };
385 #[cfg(feature = "regex")]
386 let matches = move |message: &BStr| -> bool { compiled_regex.is_match(message) };
387 394
388 match self.objs[self.idx].as_mut() {395 match self.objs[self.idx].as_mut() {
389 Some(objs) => {396 Some(objs) => {
git-repository/src/revision/walk.rs+5−0
@@ -29,6 +29,11 @@ impl<'repo> Platform<'repo> { · 28 unmodified lines
29/// Produce the iterator29/// Produce the iterator
30impl<'repo> Platform<'repo> {30impl<'repo> Platform<'repo> {
31 /// Return an iterator to traverse all commits reachable as configured by the [Platform].31 /// Return an iterator to traverse all commits reachable as configured by the [Platform].
32 ///
33 /// # Performance
34 ///
35 /// It's highly recommended to set an [`object cache`][Repository::object_cache_size()] on the parent repo
36 /// to greatly speed up performance if the returned id is supposed to be looked up right after.
32 pub fn all(self) -> Result<revision::Walk<'repo>, git_traverse::commit::ancestors::Error> {37 pub fn all(self) -> Result<revision::Walk<'repo>, git_traverse::commit::ancestors::Error> {
33 let Platform {38 let Platform {
34 repo,39 repo,