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
375375 #[cfg(not(feature = "regex"))]
376376 let matches = |message: &BStr| -> bool { message.contains_str(regex) };
377377 #[cfg(feature = "regex")]
378− let compiled_regex = match regex::bytes::Regex::new(regex.to_str_lossy().as_ref()) {
379− Ok(regex) => regex,
378+ let matches = match regex::bytes::Regex::new(regex.to_str_lossy().as_ref()) {
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+ }
380389 Err(err) => {
381390 self.err.push(err.into());
382391 return None;
383392 }
384393 };
385− #[cfg(feature = "regex")]
386− let matches = move |message: &BStr| -> bool { compiled_regex.is_match(message) };
387394
388395 match self.objs[self.idx].as_mut() {
389396 Some(objs) => {
git-repository/src/revision/walk.rs+5−0
@@ -29,6 +29,11 @@ impl<'repo> Platform<'repo> { · 28 unmodified lines
2929 /// Produce the iterator
3030 impl<'repo> Platform<'repo> {
3131 /// 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.
3237 pub fn all(self) -> Result<revision::Walk<'repo>, git_traverse::commit::ancestors::Error> {
3338 let Platform {
3439 repo,