11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4- use num_traits:: ToPrimitive ;
4+ use num_traits:: AsPrimitive ;
55use vortex_buffer:: BitBufferMut ;
66use vortex_dtype:: IntegerPType ;
77use vortex_dtype:: Nullability ;
8- use vortex_dtype:: { match_each_integer_ptype, match_smallest_offset_type} ;
8+ use vortex_dtype:: match_each_integer_ptype;
9+ use vortex_dtype:: match_smallest_offset_type;
910use vortex_error:: VortexExpect ;
1011use vortex_error:: VortexResult ;
11- use vortex_error:: vortex_panic;
1212use vortex_mask:: Mask ;
1313
1414use crate :: Array ;
@@ -48,17 +48,9 @@ impl TakeKernel for ListVTable {
4848 let total_count = indices_slice
4949 . iter( )
5050 . map( |idx| {
51- let idx = idx. to_usize( ) . unwrap_or_else( || {
52- vortex_panic!( "Failed to convert index to usize: {}" , idx)
53- } ) ;
54- ( offsets_slice[ idx + 1 ] - offsets_slice[ idx] )
55- . to_usize( )
56- . unwrap_or_else( || {
57- vortex_panic!(
58- "Failed to convert offset difference to usize: {}" ,
59- offsets_slice[ idx + 1 ] - offsets_slice[ idx]
60- )
61- } )
51+ let idx: usize = idx. as_( ) ;
52+ let diff: usize = ( offsets_slice[ idx + 1 ] - offsets_slice[ idx] ) . as_( ) ;
53+ diff
6254 } )
6355 . sum:: <usize >( ) ;
6456
@@ -106,9 +98,7 @@ fn _take<I: IntegerPType, O: IntegerPType, AccumType: IntegerPType>(
10698 new_offsets. append_zero ( ) ;
10799
108100 for & data_idx in indices {
109- let data_idx = data_idx
110- . to_usize ( )
111- . unwrap_or_else ( || vortex_panic ! ( "Failed to convert index to usize: {}" , data_idx) ) ;
101+ let data_idx: usize = data_idx. as_ ( ) ;
112102
113103 let start = offsets[ data_idx] ;
114104 let stop = offsets[ data_idx + 1 ] ;
@@ -118,21 +108,14 @@ fn _take<I: IntegerPType, O: IntegerPType, AccumType: IntegerPType>(
118108 // We could convert start and end to usize, but that would impose a potentially
119109 // harder constraint - now we don't care if they fit into usize as long as their
120110 // difference does.
121- let additional = ( stop - start) . to_usize ( ) . unwrap_or_else ( || {
122- vortex_panic ! ( "Failed to convert range length to usize: {}" , stop - start)
123- } ) ;
111+ let additional: usize = ( stop - start) . as_ ( ) ;
124112
125113 elements_to_take. reserve_exact ( additional) ;
126114 for i in 0 ..additional {
127115 elements_to_take. append_value ( start + O :: from_usize ( i) . vortex_expect ( "i < additional" ) ) ;
128116 }
129- current_offset += AccumType :: from_usize ( ( stop - start) . to_usize ( ) . unwrap_or_else ( || {
130- vortex_panic ! (
131- "Failed to convert offset difference to usize: {}" ,
132- stop - start
133- )
134- } ) )
135- . vortex_expect ( "offset conversion" ) ;
117+ current_offset +=
118+ AccumType :: from_usize ( ( stop - start) . as_ ( ) ) . vortex_expect ( "offset conversion" ) ;
136119 new_offsets. append_value ( current_offset) ;
137120 }
138121
@@ -185,9 +168,7 @@ fn _take_nullable<I: IntegerPType, O: IntegerPType, AccumType: IntegerPType>(
185168 continue ;
186169 }
187170
188- let data_idx = data_idx
189- . to_usize ( )
190- . unwrap_or_else ( || vortex_panic ! ( "Failed to convert index to usize: {}" , data_idx) ) ;
171+ let data_idx: usize = data_idx. as_ ( ) ;
191172
192173 if !data_validity. value ( data_idx) {
193174 new_offsets. append_value ( current_offset) ;
@@ -199,21 +180,14 @@ fn _take_nullable<I: IntegerPType, O: IntegerPType, AccumType: IntegerPType>(
199180 let stop = offsets[ data_idx + 1 ] ;
200181
201182 // See the note it the `take` on the reasoning
202- let additional = ( stop - start) . to_usize ( ) . unwrap_or_else ( || {
203- vortex_panic ! ( "Failed to convert range length to usize: {}" , stop - start)
204- } ) ;
183+ let additional: usize = ( stop - start) . as_ ( ) ;
205184
206185 elements_to_take. reserve_exact ( additional) ;
207186 for i in 0 ..additional {
208187 elements_to_take. append_value ( start + O :: from_usize ( i) . vortex_expect ( "i < additional" ) ) ;
209188 }
210- current_offset += AccumType :: from_usize ( ( stop - start) . to_usize ( ) . unwrap_or_else ( || {
211- vortex_panic ! (
212- "Failed to convert offset difference to usize: {}" ,
213- stop - start
214- )
215- } ) )
216- . vortex_expect ( "offset conversion" ) ;
189+ current_offset +=
190+ AccumType :: from_usize ( ( stop - start) . as_ ( ) ) . vortex_expect ( "offset conversion" ) ;
217191 new_offsets. append_value ( current_offset) ;
218192 new_validity. set ( idx) ;
219193 }
0 commit comments