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.)
This commit is contained in:
bors 2015-05-05 03:01:29 +00:00
commit 0be117e273

View file

@ -210,15 +210,13 @@ impl BitVec {
assert_eq!(self.len(), other.len());
// This could theoretically be a `debug_assert!`.
assert_eq!(self.storage.len(), other.storage.len());
let mut changed = false;
let mut changed_bits = 0;
for (a, b) in self.blocks_mut().zip(other.blocks()) {
let w = op(*a, b);
if *a != w {
changed = true;
*a = w;
}
changed_bits |= *a ^ w;
*a = w;
}
changed
changed_bits != 0
}
/// Iterator over mutable refs to the underlying blocks of data.