tustvold commented on a change in pull request #1054:
URL: https://github.com/apache/arrow-rs/pull/1054#discussion_r776324475
##########
File path: arrow/src/array/builder.rs
##########
@@ -398,6 +400,117 @@ impl BooleanBufferBuilder {
}
}
+ /// Append `count` bits from `to_set`
+ ///
+ /// `to_set` is a slice of bits packed LSB-first into `[u8]`
+ ///
+ /// # Panics
+ ///
+ /// Panics if `to_set` does not contain `ceil(count / 8)` bytes
+ #[inline]
+ pub fn append_packed(&mut self, count: usize, to_set: &[u8]) {
+ assert_eq!((count + 7) >> 3, to_set.len());
+
+ let new_len = self.len + count;
+ let new_buf_len = (new_len + 7) >> 3;
+ self.buffer.reserve(new_buf_len - self.buffer.len());
+
+ let whole_bytes = count >> 3;
+ let overrun = count & 7;
+
+ let skew = self.len & 7;
+ if skew == 0 {
+ self.buffer.extend_from_slice(&to_set[..whole_bytes]);
+ if overrun > 0 {
+ let masked = to_set[whole_bytes] & ((1 << overrun) - 1);
+ self.buffer.push(masked)
+ }
+
+ self.len = new_len;
+ debug_assert_eq!(self.buffer.len(), new_buf_len);
+ return;
+ }
+
+ for to_set_byte in &to_set[..whole_bytes] {
+ let low = *to_set_byte << skew;
+ let high = *to_set_byte >> (8 - skew);
+
+ *self.buffer.last_mut().unwrap() |= low;
Review comment:
I'd somewhat hope that LLVM would be smart enough to perform this
optimisation itself, will confirm this once I get to polishing this up for
final review in #1039
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]