changeset 41725:70827ebba453

rust: less set lookups in AncestorsIterator This uses the boolean return of `HashSet::insert()` to factor pairs of contains()/insert() into a single insert() On the mozilla-central repository (450k changesets), I get about a bit more than 10% better medians in perfancestors (taking the mean of three runs) Best run for parent changeset: ! wall 0.106474 comb 0.110000 user 0.110000 sys 0.000000 (median of 93) Best run for this changeset: ! wall 0.093191 comb 0.090000 user 0.090000 sys 0.000000 (median of 100) Differential Revision: https://phab.mercurial-scm.org/D5942
author Georges Racinet <georges.racinet@octobus.net>
date Mon, 04 Feb 2019 11:39:28 +0100
parents 9de6c4f61608
children fccb61a1777b
files rust/hg-core/src/ancestors.rs
diffstat 1 files changed, 2 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/ancestors.rs	Fri Feb 15 17:36:57 2019 +0300
+++ b/rust/hg-core/src/ancestors.rs	Mon Feb 04 11:39:28 2019 +0100
@@ -79,8 +79,7 @@
 
     #[inline]
     fn conditionally_push_rev(&mut self, rev: Revision) {
-        if self.stoprev <= rev && !self.seen.contains(&rev) {
-            self.seen.insert(rev);
+        if self.stoprev <= rev && self.seen.insert(rev) {
             self.visit.push(rev);
         }
     }
@@ -154,11 +153,10 @@
             Ok(ps) => ps,
             Err(e) => return Some(Err(e)),
         };
-        if p1 < self.stoprev || self.seen.contains(&p1) {
+        if p1 < self.stoprev || !self.seen.insert(p1) {
             self.visit.pop();
         } else {
             *(self.visit.peek_mut().unwrap()) = p1;
-            self.seen.insert(p1);
         };
 
         self.conditionally_push_rev(p2);