match: small tweak to PatternMatcher.visit_children_set stable
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Fri, 12 Apr 2024 14:17:10 +0100
branchstable
changeset 51567 cae0be933434
parent 51566 529a655874fb
child 51568 2a89d2f6336f
match: small tweak to PatternMatcher.visit_children_set This makes it a bit more efficient (avoid a computation in case of early return), and in my opinion clearer.
rust/hg-core/src/matchers.rs
--- a/rust/hg-core/src/matchers.rs	Fri Apr 12 14:09:55 2024 +0100
+++ b/rust/hg-core/src/matchers.rs	Fri Apr 12 14:17:10 2024 +0100
@@ -354,9 +354,12 @@
         if self.prefix && self.files.contains(directory) {
             return VisitChildrenSet::Recursive;
         }
-        let path_or_parents_in_set = dir_ancestors(directory)
-            .any(|parent_dir| self.files.contains(parent_dir));
-        if self.dirs.contains(directory) || path_or_parents_in_set {
+        if self.dirs.contains(directory) {
+            return VisitChildrenSet::This;
+        }
+        if dir_ancestors(directory)
+            .any(|parent_dir| self.files.contains(parent_dir))
+        {
             VisitChildrenSet::This
         } else {
             VisitChildrenSet::Empty