@@ -655,70 +655,6 @@ pub fn compare_byte_view<T: ByteViewType>(
655
655
unsafe { GenericByteViewArray :: compare_unchecked ( left, left_idx, right, right_idx) }
656
656
}
657
657
658
- /// Comparing two [`GenericByteViewArray`] at index `left_idx` and `right_idx`
659
- ///
660
- /// Comparing two ByteView types are non-trivial.
661
- /// It takes a bit of patience to understand why we don't just compare two &[u8] directly.
662
- ///
663
- /// ByteView types give us the following two advantages, and we need to be careful not to lose them:
664
- /// (1) For string/byte smaller than 12 bytes, the entire data is inlined in the view.
665
- /// Meaning that reading one array element requires only one memory access
666
- /// (two memory access required for StringArray, one for offset buffer, the other for value buffer).
667
- ///
668
- /// (2) For string/byte larger than 12 bytes, we can still be faster than (for certain operations) StringArray/ByteArray,
669
- /// thanks to the inlined 4 bytes.
670
- /// Consider equality check:
671
- /// If the first four bytes of the two strings are different, we can return false immediately (with just one memory access).
672
- ///
673
- /// If we directly compare two &[u8], we materialize the entire string (i.e., make multiple memory accesses), which might be unnecessary.
674
- /// - Most of the time (eq, ord), we only need to look at the first 4 bytes to know the answer,
675
- /// e.g., if the inlined 4 bytes are different, we can directly return unequal without looking at the full string.
676
- ///
677
- /// # Order check flow
678
- /// (1) if both string are smaller than 12 bytes, we can directly compare the data inlined to the view.
679
- /// (2) if any of the string is larger than 12 bytes, we need to compare the full string.
680
- /// (2.1) if the inlined 4 bytes are different, we can return the result immediately.
681
- /// (2.2) o.w., we need to compare the full string.
682
- ///
683
- /// # Safety
684
- /// The left/right_idx must within range of each array
685
- #[ deprecated(
686
- since = "52.2.0" ,
687
- note = "Use `GenericByteViewArray::compare_unchecked` instead"
688
- ) ]
689
- pub unsafe fn compare_byte_view_unchecked < T : ByteViewType > (
690
- left : & GenericByteViewArray < T > ,
691
- left_idx : usize ,
692
- right : & GenericByteViewArray < T > ,
693
- right_idx : usize ,
694
- ) -> std:: cmp:: Ordering {
695
- let l_view = left. views ( ) . get_unchecked ( left_idx) ;
696
- let l_len = * l_view as u32 ;
697
-
698
- let r_view = right. views ( ) . get_unchecked ( right_idx) ;
699
- let r_len = * r_view as u32 ;
700
-
701
- if l_len <= 12 && r_len <= 12 {
702
- let l_data = unsafe { GenericByteViewArray :: < T > :: inline_value ( l_view, l_len as usize ) } ;
703
- let r_data = unsafe { GenericByteViewArray :: < T > :: inline_value ( r_view, r_len as usize ) } ;
704
- return l_data. cmp ( r_data) ;
705
- }
706
-
707
- // one of the string is larger than 12 bytes,
708
- // we then try to compare the inlined data first
709
- let l_inlined_data = unsafe { GenericByteViewArray :: < T > :: inline_value ( l_view, 4 ) } ;
710
- let r_inlined_data = unsafe { GenericByteViewArray :: < T > :: inline_value ( r_view, 4 ) } ;
711
- if r_inlined_data != l_inlined_data {
712
- return l_inlined_data. cmp ( r_inlined_data) ;
713
- }
714
-
715
- // unfortunately, we need to compare the full data
716
- let l_full_data: & [ u8 ] = unsafe { left. value_unchecked ( left_idx) . as_ref ( ) } ;
717
- let r_full_data: & [ u8 ] = unsafe { right. value_unchecked ( right_idx) . as_ref ( ) } ;
718
-
719
- l_full_data. cmp ( r_full_data)
720
- }
721
-
722
658
#[ cfg( test) ]
723
659
mod tests {
724
660
use std:: sync:: Arc ;
0 commit comments