alamb commented on code in PR #5619:
URL: https://github.com/apache/arrow-rs/pull/5619#discussion_r1558180439
##########
arrow-array/src/builder/generic_bytes_view_builder.rs:
##########
@@ -72,35 +72,28 @@ impl<T: ByteViewType + ?Sized> GenericByteViewBuilder<T> {
#[inline]
pub fn append_value(&mut self, value: impl AsRef<T::Native>) {
let v: &[u8] = value.as_ref().as_ref();
- let length: u32 = v.len().try_into().unwrap();
- if length <= 12 {
- let mut view_buffer = [0; 16];
- view_buffer[0..4].copy_from_slice(&length.to_le_bytes());
- view_buffer[4..4 + v.len()].copy_from_slice(v);
- self.views_builder.append(u128::from_le_bytes(view_buffer));
- self.null_buffer_builder.append_non_null();
- return;
- }
- let required_cap = self.in_progress.len() + v.len();
- if self.in_progress.capacity() < required_cap {
- let in_progress = Vec::with_capacity(v.len().max(self.block_size
as usize));
- let flushed = std::mem::replace(&mut self.in_progress,
in_progress);
- if !flushed.is_empty() {
- assert!(self.completed.len() < u32::MAX as usize);
- self.completed.push(flushed.into());
+ let view: u128 = match View::from(v) {
Review Comment:
I was trying to encapsulate the logic of converting to/from u128 / figuring
out which type of view it was into the type system
I like how this looks now and I think it is easier to follow
--
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]