@@ -113,24 +113,9 @@ impl<O: IntegerPType> VarBinBuilder<O> {
113113 fn append_values_with_lengths (
114114 & mut self ,
115115 values : & [ u8 ] ,
116- lengths : impl Iterator < Item = usize > + Clone ,
116+ lengths : impl Iterator < Item = usize > ,
117117 validity : & Mask ,
118118 ) {
119- let total_len = lengths
120- . clone ( )
121- . try_fold ( 0usize , |total, len| total. checked_add ( len) )
122- . unwrap_or_else ( || vortex_panic ! ( "VarBin byte length overflow" ) ) ;
123- let final_end = self
124- . data
125- . len ( )
126- . checked_add ( total_len)
127- . unwrap_or_else ( || vortex_panic ! ( "VarBin byte offset overflow" ) ) ;
128- O :: from ( final_end) . unwrap_or_else ( || {
129- vortex_panic ! (
130- "Failed to convert byte offset {final_end} to {}" ,
131- std:: any:: type_name:: <O >( )
132- )
133- } ) ;
134119 let mut end = self . data . len ( ) ;
135120 let mut len = 0 ;
136121 for value_len in lengths {
@@ -234,16 +219,10 @@ impl VarBinBufferBuilder {
234219 }
235220
236221 /// Appends decompressed values represented by one contiguous byte buffer and per-row lengths.
237- ///
238- /// # Safety
239- ///
240- /// `lengths` must contain exactly `validity.len()` items whose sum is `values.len()`.
241- /// Non-nullable builders require an all-valid mask. For UTF-8 builders, every valid value
242- /// identified by `lengths` must be valid UTF-8.
243- pub unsafe fn append_values_unchecked (
222+ pub fn append_values (
244223 & mut self ,
245224 values : & [ u8 ] ,
246- lengths : impl Iterator < Item = usize > + Clone ,
225+ lengths : impl Iterator < Item = usize > ,
247226 validity : & Mask ,
248227 ) {
249228 match & mut self . storage {
@@ -257,11 +236,7 @@ impl VarBinBufferBuilder {
257236 }
258237
259238 /// Appends the same non-null value `n` times.
260- ///
261- /// # Safety
262- ///
263- /// For a UTF-8 builder, `value` must be valid UTF-8.
264- pub unsafe fn append_n_values_unchecked ( & mut self , value : impl AsRef < [ u8 ] > , n : usize ) {
239+ pub fn append_n_values ( & mut self , value : impl AsRef < [ u8 ] > , n : usize ) {
265240 let value = value. as_ref ( ) ;
266241 for _ in 0 ..n {
267242 self . append_value ( value) ;
@@ -278,13 +253,11 @@ impl VarBinBufferBuilder {
278253 ) ;
279254 match self . dtype ( ) {
280255 DType :: Utf8 ( _) => match scalar. as_utf8 ( ) . value ( ) {
281- // SAFETY: Utf8Scalar values are valid UTF-8.
282- Some ( value) => unsafe { self . append_n_values_unchecked ( value, n) } ,
256+ Some ( value) => self . append_n_values ( value, n) ,
283257 None => self . push_nulls ( n) ,
284258 } ,
285259 DType :: Binary ( _) => match scalar. as_binary ( ) . value ( ) {
286- // SAFETY: Binary builders accept arbitrary bytes.
287- Some ( value) => unsafe { self . append_n_values_unchecked ( value, n) } ,
260+ Some ( value) => self . append_n_values ( value, n) ,
288261 None => self . push_nulls ( n) ,
289262 } ,
290263 dtype => vortex_bail ! ( "VarBinBufferBuilder cannot append scalar of dtype {dtype}" ) ,
@@ -298,31 +271,22 @@ impl VarBinBufferBuilder {
298271 array : crate :: ArrayView < ' _ , VarBin > ,
299272 ctx : & mut ExecutionCtx ,
300273 ) -> VortexResult < ( ) > {
301- vortex_ensure ! (
302- array. dtype( ) == self . dtype( ) ,
303- "VarBinBufferBuilder expected array with dtype {}, got {}" ,
304- self . dtype( ) ,
305- array. dtype( )
306- ) ;
307274 let offsets = array. offsets ( ) . clone ( ) . execute :: < PrimitiveArray > ( ctx) ?;
308275 let bytes: ByteBuffer = array. sliced_bytes ( ) ;
309276 let validity = array
310277 . varbin_validity ( )
311278 . execute_mask ( array. as_ref ( ) . len ( ) , ctx) ?;
312279 crate :: match_each_integer_ptype!( offsets. ptype( ) , |P | {
313280 let offsets = offsets. as_slice:: <P >( ) ;
314- // SAFETY: VarBinArray guarantees matching offsets, bytes, validity, and UTF-8.
315- unsafe {
316- self . append_values_unchecked(
317- bytes. as_slice( ) ,
318- offsets. windows( 2 ) . map( |window| {
319- let start: usize = window[ 0 ] . as_( ) ;
320- let end: usize = window[ 1 ] . as_( ) ;
321- end - start
322- } ) ,
323- & validity,
324- ) ;
325- }
281+ self . append_values(
282+ bytes. as_slice( ) ,
283+ offsets. windows( 2 ) . map( |window| {
284+ let start: usize = window[ 0 ] . as_( ) ;
285+ let end: usize = window[ 1 ] . as_( ) ;
286+ end - start
287+ } ) ,
288+ & validity,
289+ ) ;
326290 } ) ;
327291 Ok ( ( ) )
328292 }
@@ -333,12 +297,6 @@ impl VarBinBufferBuilder {
333297 array : crate :: ArrayView < ' _ , VarBinView > ,
334298 ctx : & mut ExecutionCtx ,
335299 ) -> VortexResult < ( ) > {
336- vortex_ensure ! (
337- array. dtype( ) == self . dtype( ) ,
338- "VarBinBufferBuilder expected array with dtype {}, got {}" ,
339- self . dtype( ) ,
340- array. dtype( )
341- ) ;
342300 let validity = array
343301 . varbinview_validity ( )
344302 . execute_mask ( array. as_ref ( ) . len ( ) , ctx) ?;
@@ -517,22 +475,6 @@ mod tests {
517475 Ok ( ( ) )
518476 }
519477
520- #[ test]
521- fn test_safe_append_rejects_dtype_mismatch ( ) {
522- let mut builder = VarBinBufferBuilder :: with_capacity ( DType :: Utf8 ( Nullable ) , false , 1 ) ;
523- let mut ctx = array_session ( ) . create_execution_ctx ( ) ;
524- let varbin = VarBinArray :: from_iter ( [ Some ( b"hello" . as_slice ( ) ) ] , DType :: Binary ( Nullable ) ) ;
525- assert ! ( builder. append_varbin( varbin. as_view( ) , & mut ctx) . is_err( ) ) ;
526-
527- let varbinview =
528- VarBinViewArray :: from_iter ( [ Some ( b"hello" . as_slice ( ) ) ] , DType :: Binary ( Nullable ) ) ;
529- assert ! (
530- builder
531- . append_varbinview( varbinview. as_view( ) , & mut ctx)
532- . is_err( )
533- ) ;
534- }
535-
536478 #[ rstest]
537479 #[ case( false ) ]
538480 #[ case( true ) ]
0 commit comments