comparison rust/hg-core/src/revlog/index.rs @ 51228:61a6ef876efd

rust-index: simplification in find_gca_candidates() `parent_seen` can be made a mutable ref, making this part more obvious, not needing to be commented so much. The micro-optimization of avoiding the union if `parent_seen` and `current_seen` agree is pushed down in the `union()` method of the fast, `u64` based bit set implementation (in case it matters).
author Georges Racinet <georges.racinet@octobus.net>
date Fri, 20 Oct 2023 08:54:49 +0200
parents e553cd209215
children 1b23aaf5eb7b
comparison
equal deleted inserted replaced
51227:e553cd209215 51228:61a6ef876efd
1139 } 1139 }
1140 for parent in self.parents(current_rev)? { 1140 for parent in self.parents(current_rev)? {
1141 if parent == NULL_REVISION { 1141 if parent == NULL_REVISION {
1142 continue; 1142 continue;
1143 } 1143 }
1144 let parent_seen = &seen[parent.0 as usize]; 1144 let parent_seen = &mut seen[parent.0 as usize];
1145 if poison { 1145 if poison {
1146 // this block is logically equivalent to poisoning parent 1146 // this block is logically equivalent to poisoning parent
1147 // and counting it as non interesting if it 1147 // and counting it as non interesting if it
1148 // has been seen before (hence counted then as interesting) 1148 // has been seen before (hence counted then as interesting)
1149 if !parent_seen.is_empty() && !parent_seen.is_poisoned() { 1149 if !parent_seen.is_empty() && !parent_seen.is_poisoned() {
1150 interesting -= 1; 1150 interesting -= 1;
1151 } 1151 }
1152 seen[parent.0 as usize].poison(); 1152 parent_seen.poison();
1153 } else { 1153 } else {
1154 // Without the `interesting` accounting, this block would
1155 // be logically equivalent to: parent_seen |= current_seen
1156 // The parent counts as interesting if it was not already
1157 // known to be an ancestor (would already have counted)
1158 if parent_seen.is_empty() { 1154 if parent_seen.is_empty() {
1159 seen[parent.0 as usize] = current_seen.clone();
1160 interesting += 1; 1155 interesting += 1;
1161 } else if *parent_seen != current_seen {
1162 seen[parent.0 as usize].union(&current_seen);
1163 } 1156 }
1157 parent_seen.union(&current_seen);
1164 } 1158 }
1165 } 1159 }
1166 1160
1167 current_rev = Revision(current_rev.0 - 1); 1161 current_rev = Revision(current_rev.0 - 1);
1168 } 1162 }
1341 fn discard(&mut self, n: usize) { 1335 fn discard(&mut self, n: usize) {
1342 (*self) &= u64::MAX - (1u64 << n); 1336 (*self) &= u64::MAX - (1u64 << n);
1343 } 1337 }
1344 1338
1345 fn union(&mut self, other: &Self) { 1339 fn union(&mut self, other: &Self) {
1346 (*self) |= *other; 1340 if *self != *other {
1341 (*self) |= *other;
1342 }
1347 } 1343 }
1348 1344
1349 fn is_full_range(&self, n: usize) -> bool { 1345 fn is_full_range(&self, n: usize) -> bool {
1350 *self + 1 == (1u64 << n) 1346 *self + 1 == (1u64 << n)
1351 } 1347 }