Commit 8d70278
committed
refactor: optimize BitBuffer::from(Vec<bool>) using 64-bit packing
Refactored the `From<&[bool]>` implementation for `BitBufferMut` to use
the same optimized packing strategy as `BitBuffer::collect_bool`.
### Performance Improvement
**Before**: Element-by-element iteration, setting individual bits one at a time
```rust
for (i, &v) in value.iter().enumerate() {
if v {
unsafe { buf.set_unchecked(i) }
}
}
```
**After**: Pack 64 booleans at a time into u64 words before writing to memory
```rust
for chunk in 0..chunks {
let mut packed = 0u64;
for bit_idx in 0..64 {
packed |= (value[i] as u64) << bit_idx;
}
unsafe { buffer.push_unchecked(packed) }
}
```
This brings the same performance optimization that production code uses
via `collect_bool` to all code paths that create `BitBuffer` from `Vec<bool>`.
### Testing
- All 50 vortex-buffer tests pass
- All 1541 vortex-array tests pass
- No clippy warnings1 parent 4552c10 commit 8d70278
1 file changed
+30
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
549 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
550 | 560 | | |
551 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
552 | 576 | | |
553 | 577 | | |
554 | 578 | | |
| |||
0 commit comments