Skip to content

Commit 0be117e

Browse files
committed
Auto merge of #25095 - huonw:faster-bitvec, r=alexcrichton
This makes the `bit::vec::bench::bench_bit_vec_big_union` benchmark go from `774 ns/iter (+/- 190)` to `602 ns/iter (+/- 5)`. (There's room for more work here too: if one can guarantee 128-bit alignment for the vector, the compiler actually optimises `union`, `intersection` etc. to SIMD instructions, which end up being ~5x faster that the original version, and 4x faster than the optimised version in this patch.)
2 parents 4356220 + 4b46546 commit 0be117e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libcollections/bit.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,13 @@ impl BitVec {
210210
assert_eq!(self.len(), other.len());
211211
// This could theoretically be a `debug_assert!`.
212212
assert_eq!(self.storage.len(), other.storage.len());
213-
let mut changed = false;
213+
let mut changed_bits = 0;
214214
for (a, b) in self.blocks_mut().zip(other.blocks()) {
215215
let w = op(*a, b);
216-
if *a != w {
217-
changed = true;
218-
*a = w;
219-
}
216+
changed_bits |= *a ^ w;
217+
*a = w;
220218
}
221-
changed
219+
changed_bits != 0
222220
}
223221

224222
/// Iterator over mutable refs to the underlying blocks of data.

0 commit comments

Comments
 (0)