Skip to content

Commit c1229f1

Browse files
committed
Apply suggestion
1 parent 03a5c15 commit c1229f1

1 file changed

Lines changed: 14 additions & 22 deletions

File tree

arrow-select/src/interleave.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -401,45 +401,37 @@ fn interleave_list_primitive_child<O: OffsetSizeTrait, T: ArrowPrimitiveType>(
401401
}
402402

403403
// Build null buffer. Pre-allocate with 0x00 (all null), then:
404-
// - Sources with nulls: set_bits ORs in valid bits from source.
404+
// - Sources with nulls: set_bits copies the source validity bits into the destination range.
405405
// - Sources without nulls: set the bit range to all 1s directly.
406406
let nulls = if has_child_nulls {
407407
let null_byte_len = bit_util::ceil(capacity, 8);
408-
let mut null_buf = MutableBuffer::new(null_byte_len);
409-
null_buf.resize(null_byte_len, 0);
408+
let mut output_null_buf = MutableBuffer::from_len_zeroed(null_byte_len);
410409

411410
let mut offset_write = 0;
412-
let mut null_count = 0usize;
411+
let mut output_null_count = 0usize;
413412
for &(array, row) in indices {
414413
let o = interleaved.arrays[array].value_offsets();
415414
let start = o[row].as_usize();
416415
let end = o[row + 1].as_usize();
417416
let len = end - start;
418417
if len > 0 {
419-
match child_arrays[array].nulls() {
420-
Some(null_buffer) => {
421-
null_count += set_bits(
422-
null_buf.as_slice_mut(),
423-
null_buffer.validity(),
424-
offset_write,
425-
null_buffer.offset() + start,
426-
len,
427-
);
428-
}
429-
None => {
430-
// For a non-nullable source, set the bit range to all 1s directly.
431-
let buf = null_buf.as_slice_mut();
432-
(offset_write..offset_write + len).for_each(|i| bit_util::set_bit(buf, i));
433-
}
418+
if let Some(null_buffer) = child_arrays[array].nulls() {
419+
output_null_count += set_bits(
420+
output_null_buf.as_slice_mut(),
421+
null_buffer.validity(),
422+
offset_write,
423+
null_buffer.offset() + start,
424+
len,
425+
);
434426
}
435427
}
436428
offset_write += len;
437429
}
438430

439-
if null_count > 0 {
440-
let bool_buf = BooleanBuffer::new(null_buf.into(), 0, capacity);
431+
if output_null_count > 0 {
432+
let bool_buf = BooleanBuffer::new(output_null_buf.into(), 0, capacity);
441433
// SAFETY: null_count is accumulated from set_bits which correctly counts unset bits
442-
Some(unsafe { NullBuffer::new_unchecked(bool_buf, null_count) })
434+
Some(unsafe { NullBuffer::new_unchecked(bool_buf, output_null_count) })
443435
} else {
444436
None
445437
}

0 commit comments

Comments
 (0)