Dandandan commented on a change in pull request #9304:
URL: https://github.com/apache/arrow/pull/9304#discussion_r563279700
##########
File path: rust/arrow/src/buffer.rs
##########
@@ -1188,6 +1209,57 @@ impl Drop for SetLenOnDrop<'_> {
}
}
+/// Creating a `MutableBuffer` instance by setting bits according to the
boolean values
+impl std::iter::FromIterator<bool> for MutableBuffer {
+ fn from_iter<I>(iter: I) -> Self
+ where
+ I: IntoIterator<Item = bool>,
+ {
+ let mut iterator = iter.into_iter();
+ let mut result = {
+ let byte_capacity: usize =
iterator.size_hint().0.saturating_add(7) / 8;
+ MutableBuffer::new(byte_capacity)
+ };
+
+ while let Some(value) = iterator.next() {
+ //we have the first bit of the byte
+ let mut exhausted = false;
+ let mut byte_accum: u8 = match value {
Review comment:
I think you could merge the `iterator.next()` loops here.
and maybe do the bit masking loop like this:
```rust
loop {
let mut byte_accum = 0;
let mut mask = 1;
while mask <= 0b10000000 {
if let Some(value) = iterator.next() {
byte_accum |= match value {
true => mask,
false => 0,
};
mask <<= 1;
} else {
exhausted = true;
break;
}
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]