22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
44use vortex:: mask:: Mask ;
5+ use vortex:: mask:: MaskValues ;
56
7+ use crate :: cpp:: duckdb_vx_vector_set_all_valid;
68use crate :: duckdb:: Value ;
79use crate :: duckdb:: VectorRef ;
810use crate :: exporter:: copy_from_slice;
@@ -11,44 +13,44 @@ impl VectorRef {
1113 pub ( super ) unsafe fn set_validity ( & mut self , mask : & Mask , offset : usize , len : usize ) -> bool {
1214 match mask {
1315 Mask :: AllTrue ( _) => {
14- // We only need to blank out validity if there is already a slice allocated.
15- // SAFETY: Caller guarantees this.
16- unsafe { self . set_all_true_validity ( len) }
16+ self . set_all_true_validity ( ) ;
1717 false
1818 }
1919 Mask :: AllFalse ( _) => {
20- // SAFETY: Caller guarantees this.
2120 self . set_all_false_validity ( ) ;
2221 true
2322 }
24- Mask :: Values ( arr) => {
25- let true_count = arr. bit_buffer ( ) . slice ( offset..( offset + len) ) . true_count ( ) ;
26- if true_count == len {
27- unsafe { self . set_all_true_validity ( len) }
28- } else if true_count == 0 {
29- self . set_all_false_validity ( )
30- } else {
31- let source = arr. bit_buffer ( ) . inner ( ) . as_slice ( ) ;
32- copy_from_slice (
33- unsafe { self . ensure_validity_slice ( len) } ,
34- source,
35- offset,
36- len,
37- ) ;
38- }
39-
40- true_count == 0
41- }
23+ Mask :: Values ( arr) => self . set_validity_with_array ( & arr, len, offset) ,
4224 }
4325 }
4426
45- pub ( super ) unsafe fn set_all_true_validity ( & mut self , len : usize ) {
46- if let Some ( validity) = unsafe { self . validity_bitslice_mut ( len) } {
47- validity. fill ( true ) ;
27+ fn set_validity_with_array ( & mut self , arr : & MaskValues , len : usize , offset : usize ) -> bool {
28+ let true_count = arr. true_count ( ) ;
29+ if true_count == len {
30+ self . set_all_true_validity ( ) ;
31+ return false ;
32+ } else if true_count == 0 {
33+ self . set_all_false_validity ( ) ;
34+ return true ;
35+ }
36+
37+ let source = arr. bit_buffer ( ) . inner ( ) . as_slice ( ) ;
38+ let dest = unsafe { self . ensure_validity_slice ( len) } ;
39+ let true_count = copy_from_slice ( dest, source, offset, len) ;
40+ if true_count == len {
41+ self . set_all_true_validity ( )
42+ } else if true_count == 0 {
43+ self . set_all_false_validity ( )
4844 }
45+
46+ true_count == 0
47+ }
48+
49+ fn set_all_true_validity ( & mut self ) {
50+ unsafe { duckdb_vx_vector_set_all_valid ( self . as_ptr ( ) ) } ;
4951 }
5052
51- pub ( super ) fn set_all_false_validity ( & mut self ) {
53+ fn set_all_false_validity ( & mut self ) {
5254 self . reference_value ( & Value :: null ( & self . logical_type ( ) ) ) ;
5355 }
5456}
0 commit comments