@@ -325,18 +325,18 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
325
325
/// and return a new array with the compacted data buffers.
326
326
/// The original array will be left as is.
327
327
pub fn gc ( & self ) -> Self {
328
- let compact_check = self . compact_check ( ) ;
328
+ let check_result = self . compact_check ( ) ;
329
329
330
- if compact_check . iter ( ) . all ( |x| * x) {
330
+ if check_result . iter ( ) . all ( |x| * x) {
331
331
return self . clone ( ) ;
332
332
}
333
333
334
334
let mut new_views = Vec :: with_capacity ( self . views . len ( ) ) ;
335
335
let mut new_bufs: Vec < Vec < u8 > > = vec ! [ vec![ ] ; self . buffers. len( ) ] ;
336
- for view in self . views . iter ( ) {
336
+ for ( i , view) in self . views . iter ( ) . enumerate ( ) {
337
337
let mut bv = ByteView :: from ( * view) ;
338
338
let idx = bv. buffer_index as usize ;
339
- if bv. length <= 12 || compact_check [ idx] {
339
+ if self . is_null ( i ) || bv. length <= 12 || check_result [ idx] {
340
340
new_views. push ( * view) ;
341
341
continue ;
342
342
}
@@ -362,7 +362,7 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
362
362
. iter ( )
363
363
. enumerate ( )
364
364
. map ( |( idx, buf) | {
365
- if compact_check [ idx] {
365
+ if check_result [ idx] {
366
366
buf. clone ( )
367
367
} else {
368
368
new_bufs[ idx] . clone ( )
@@ -604,14 +604,15 @@ impl From<Vec<Option<String>>> for StringViewArray {
604
604
/// Then it is better to do the check at once, rather than doing it for each accumulate operation.
605
605
struct CompactChecker {
606
606
length : usize ,
607
- coverage : BTreeMap < usize , usize > ,
607
+ intervals : BTreeMap < usize , usize > ,
608
608
}
609
609
610
610
impl CompactChecker {
611
+ /// Create a new checker with the expected length of the buffer
611
612
pub fn new ( length : usize ) -> Self {
612
613
Self {
613
614
length,
614
- coverage : BTreeMap :: new ( ) ,
615
+ intervals : BTreeMap :: new ( ) ,
615
616
}
616
617
}
617
618
@@ -621,21 +622,21 @@ impl CompactChecker {
621
622
return ;
622
623
}
623
624
let end = offset + length;
624
- if let Some ( val) = self . coverage . get_mut ( & offset) {
625
+ if let Some ( val) = self . intervals . get_mut ( & offset) {
625
626
if * val < end {
626
627
* val = end;
627
628
}
628
629
} else {
629
- self . coverage . insert ( offset, end) ;
630
+ self . intervals . insert ( offset, end) ;
630
631
}
631
632
}
632
633
633
634
/// Check if the checker is fully covered
634
- pub fn finish ( & self ) -> bool {
635
+ pub fn finish ( self ) -> bool {
635
636
// check if the coverage is continuous and full
636
637
let mut last_end = 0 ;
637
638
// todo: can be optimized
638
- for ( start, end) in self . coverage . iter ( ) {
639
+ for ( start, end) in self . intervals . iter ( ) {
639
640
if * start > last_end {
640
641
return false ;
641
642
}
0 commit comments