diff options
| author | bors <bors@rust-lang.org> | 2015-05-05 03:01:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-05 03:01:29 +0000 |
| commit | 0be117e2733423e70bccd8b0a46e8eccd1e1d1cc (patch) | |
| tree | 0df94bedead37a258dbfc7853b7053df96f61b99 | |
| parent | 435622028f37085819843f4ac8938557501f0468 (diff) | |
| parent | 4b46546af0d230a56b4f66d0fcc2ede7b89c09b5 (diff) | |
| download | rust-0be117e2733423e70bccd8b0a46e8eccd1e1d1cc.tar.gz rust-0be117e2733423e70bccd8b0a46e8eccd1e1d1cc.zip | |
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.)
| -rw-r--r-- | src/libcollections/bit.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index d9151298a35..ba3e144e628 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -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. |
