From 747c56c2c3cc56574210bf013ac6d5863b08266c Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Thu, 6 May 2021 16:19:38 -0700 Subject: [PATCH] Some micro-optimizations in BitVec. --- src/bitvec.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bitvec.rs b/src/bitvec.rs index 9260e1b..5a1c949 100644 --- a/src/bitvec.rs +++ b/src/bitvec.rs @@ -83,14 +83,16 @@ impl BitVec { let last_idx = other.bits.len() - 1; self.ensure_idx(last_idx); - let mut changed = false; + let mut changed = 0; for (self_word, other_word) in self.bits.iter_mut().zip(other.bits.iter()) { - if *other_word & !*self_word != 0 { - changed = true; + if *other_word == 0 { + // Avoid cache misses in `self` if `other` is zeroes. + continue; } + changed |= *other_word & !*self_word; *self_word |= *other_word; } - changed + changed != 0 } pub fn and(&mut self, other: &Self) {