Skip to content

Commit f3d5f09

Browse files
authored
Collect slots directly into smallvec instead of using vec and into (#7847)
These copies are unnecessary Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent d0d9a8b commit f3d5f09

17 files changed

Lines changed: 51 additions & 38 deletions

File tree

encodings/datetime-parts/src/array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use vortex_array::dtype::Nullability;
2828
use vortex_array::dtype::PType;
2929
use vortex_array::require_child;
3030
use vortex_array::serde::ArrayChildren;
31+
use vortex_array::smallvec::smallvec;
3132
use vortex_array::vtable::VTable;
3233
use vortex_array::vtable::ValidityChild;
3334
use vortex_array::vtable::ValidityVTableFromChild;
@@ -169,7 +170,7 @@ impl VTable for DateTimeParts {
169170
len,
170171
)?;
171172

172-
let slots = vec![Some(days), Some(seconds), Some(subseconds)];
173+
let slots = smallvec![Some(days), Some(seconds), Some(subseconds)];
173174
let data = DateTimePartsData {};
174175
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
175176
}
@@ -275,7 +276,7 @@ impl DateTimeParts {
275276
) -> VortexResult<DateTimePartsArray> {
276277
let len = days.len();
277278
DateTimePartsData::validate(&dtype, &days, &seconds, &subseconds, len)?;
278-
let slots = vec![Some(days), Some(seconds), Some(subseconds)];
279+
let slots = smallvec![Some(days), Some(seconds), Some(subseconds)];
279280
let data = DateTimePartsData {};
280281
Ok(unsafe {
281282
Array::from_parts_unchecked(

encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use vortex_array::scalar::DecimalValue;
3333
use vortex_array::scalar::Scalar;
3434
use vortex_array::scalar::ScalarValue;
3535
use vortex_array::serde::ArrayChildren;
36+
use vortex_array::smallvec::smallvec;
3637
use vortex_array::vtable::OperationsVTable;
3738
use vortex_array::vtable::VTable;
3839
use vortex_array::vtable::ValidityChild;
@@ -144,7 +145,7 @@ impl VTable for DecimalByteParts {
144145
"lower_part_count > 0 not currently supported"
145146
);
146147

147-
let slots = vec![Some(msp.clone())];
148+
let slots = smallvec![Some(msp.clone())];
148149
let data = DecimalBytePartsData::try_new(msp.dtype(), msp.len(), *decimal_dtype)?;
149150
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
150151
}
@@ -262,7 +263,7 @@ impl DecimalByteParts {
262263
) -> VortexResult<DecimalBytePartsArray> {
263264
let len = msp.len();
264265
let dtype = DType::Decimal(decimal_dtype, msp.dtype().nullability());
265-
let slots = vec![Some(msp.clone())];
266+
let slots = smallvec![Some(msp.clone())];
266267
let data = DecimalBytePartsData::try_new(msp.dtype(), msp.len(), decimal_dtype)?;
267268
Ok(unsafe {
268269
Array::from_parts_unchecked(

encodings/fastlanes/src/delta/vtable/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use vortex_array::dtype::DType;
2323
use vortex_array::dtype::PType;
2424
use vortex_array::match_each_unsigned_integer_ptype;
2525
use vortex_array::serde::ArrayChildren;
26+
use vortex_array::smallvec::smallvec;
2627
use vortex_array::vtable::VTable;
2728
use vortex_error::VortexExpect;
2829
use vortex_error::VortexResult;
@@ -168,7 +169,7 @@ impl VTable for Delta {
168169
let deltas = children.get(1, dtype, deltas_len)?;
169170

170171
let data = DeltaData::try_new(metadata.offset as usize)?;
171-
let slots = vec![Some(bases), Some(deltas)];
172+
let slots = smallvec![Some(bases), Some(deltas)];
172173
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
173174
}
174175

@@ -191,7 +192,7 @@ impl Delta {
191192
) -> VortexResult<DeltaArray> {
192193
let dtype = bases.dtype().with_nullability(deltas.dtype().nullability());
193194
let data = DeltaData::try_new(offset)?;
194-
let slots = vec![Some(bases), Some(deltas)];
195+
let slots = smallvec![Some(bases), Some(deltas)];
195196
Array::try_from_parts(ArrayParts::new(Delta, dtype, len, data).with_slots(slots))
196197
}
197198

encodings/fastlanes/src/for/vtable/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use vortex_array::dtype::DType;
2222
use vortex_array::scalar::Scalar;
2323
use vortex_array::scalar::ScalarValue;
2424
use vortex_array::serde::ArrayChildren;
25+
use vortex_array::smallvec::smallvec;
2526
use vortex_array::vtable::VTable;
2627
use vortex_array::vtable::ValidityVTableFromChild;
2728
use vortex_error::VortexExpect;
@@ -132,7 +133,7 @@ impl VTable for FoR {
132133
let scalar_value = ScalarValue::from_proto_bytes(metadata, dtype, session)?;
133134
let reference = Scalar::try_new(dtype.clone(), scalar_value)?;
134135
let encoded = children.get(0, dtype, len)?;
135-
let slots = vec![Some(encoded)];
136+
let slots = smallvec![Some(encoded)];
136137

137138
let data = FoRData::try_new(reference)?;
138139
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
@@ -173,7 +174,7 @@ impl FoR {
173174
let reference = reference.cast(&dtype)?;
174175
let len = encoded.len();
175176
let data = FoRData::try_new(reference)?;
176-
let slots = vec![Some(encoded)];
177+
let slots = smallvec![Some(encoded)];
177178
Array::try_from_parts(ArrayParts::new(FoR, dtype, len, data).with_slots(slots))
178179
}
179180

encodings/fastlanes/src/rle/vtable/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use vortex_array::dtype::DType;
2222
use vortex_array::dtype::Nullability;
2323
use vortex_array::dtype::PType;
2424
use vortex_array::serde::ArrayChildren;
25+
use vortex_array::smallvec::smallvec;
2526
use vortex_array::vtable::VTable;
2627
use vortex_error::VortexExpect;
2728
use vortex_error::VortexResult;
@@ -186,7 +187,7 @@ impl VTable for RLE {
186187
usize::try_from(metadata.values_idx_offsets_len)?,
187188
)?;
188189

189-
let slots = vec![Some(values), Some(indices), Some(values_idx_offsets)];
190+
let slots = smallvec![Some(values), Some(indices), Some(values_idx_offsets)];
190191
let data = RLEData::try_new(metadata.offset as usize)?;
191192
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
192193
}
@@ -219,7 +220,7 @@ impl RLE {
219220
length: usize,
220221
) -> VortexResult<RLEArray> {
221222
let dtype = DType::Primitive(values.dtype().as_ptype(), indices.dtype().nullability());
222-
let slots = vec![Some(values), Some(indices), Some(values_idx_offsets)];
223+
let slots = smallvec![Some(values), Some(indices), Some(values_idx_offsets)];
223224
let data = RLEData::try_new(offset)?;
224225
Array::try_from_parts(ArrayParts::new(RLE, dtype, length, data).with_slots(slots))
225226
}
@@ -236,7 +237,7 @@ impl RLE {
236237
length: usize,
237238
) -> RLEArray {
238239
let dtype = DType::Primitive(values.dtype().as_ptype(), indices.dtype().nullability());
239-
let slots = vec![Some(values), Some(indices), Some(values_idx_offsets)];
240+
let slots = smallvec![Some(values), Some(indices), Some(values_idx_offsets)];
240241
let data = unsafe { RLEData::new_unchecked(offset) };
241242
unsafe {
242243
Array::from_parts_unchecked(ArrayParts::new(RLE, dtype, length, data).with_slots(slots))

encodings/fsst/src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl VTable for FSST {
252252
len,
253253
&mut ctx,
254254
)?;
255-
let slots = vec![
255+
let slots = smallvec![
256256
Some(uncompressed_lengths),
257257
Some(codes_offsets),
258258
validity_to_child(&codes_validity, len),

encodings/parquet-variant/src/array.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use vortex_array::arrow::FromArrowArray;
2121
use vortex_array::arrow::to_arrow_null_buffer;
2222
use vortex_array::dtype::DType;
2323
use vortex_array::dtype::Nullability;
24+
use vortex_array::smallvec::smallvec;
2425
use vortex_array::validity::Validity;
2526
use vortex_array::vtable::child_to_validity;
2627
use vortex_array::vtable::validity_to_child;
@@ -95,7 +96,7 @@ impl ParquetVariant {
9596
&dtype,
9697
len,
9798
)?;
98-
let slots = vec![
99+
let slots = smallvec![
99100
validity_to_child(&validity, len),
100101
Some(metadata),
101102
value,

encodings/parquet-variant/src/vtable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_array::buffer::BufferHandle;
2020
use vortex_array::dtype::DType;
2121
use vortex_array::dtype::Nullability;
2222
use vortex_array::serde::ArrayChildren;
23+
use vortex_array::smallvec::smallvec;
2324
use vortex_array::validity::Validity;
2425
use vortex_array::vtable::VTable;
2526
use vortex_array::vtable::child_to_validity;
@@ -200,7 +201,7 @@ impl VTable for ParquetVariant {
200201
dtype,
201202
len,
202203
)?;
203-
let slots = vec![
204+
let slots = smallvec![
204205
validity_to_child(&validity, len),
205206
Some(variant_metadata),
206207
value,

encodings/pco/src/array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use vortex_array::dtype::PType;
3737
use vortex_array::dtype::half;
3838
use vortex_array::scalar::Scalar;
3939
use vortex_array::serde::ArrayChildren;
40+
use vortex_array::smallvec::smallvec;
4041
use vortex_array::validity::Validity;
4142
use vortex_array::vtable::OperationsVTable;
4243
use vortex_array::vtable::VTable;
@@ -206,7 +207,7 @@ impl VTable for Pco {
206207
.sum::<usize>();
207208
vortex_ensure!(pages.len() == expected_n_pages);
208209

209-
let slots = vec![validity_to_child(&validity, len)];
210+
let slots = smallvec![validity_to_child(&validity, len)];
210211
let data = PcoData::new(chunk_metas, pages, dtype.as_ptype(), metadata, len);
211212
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
212213
}
@@ -291,7 +292,7 @@ impl Pco {
291292
) -> VortexResult<PcoArray> {
292293
let len = data.len();
293294
data.validate(&dtype, len, &validity)?;
294-
let slots = vec![validity_to_child(&validity, data.unsliced_n_rows())];
295+
let slots = smallvec![validity_to_child(&validity, data.unsliced_n_rows())];
295296
Ok(unsafe {
296297
Array::from_parts_unchecked(ArrayParts::new(Pco, dtype, len, data).with_slots(slots))
297298
})

encodings/runend/src/array.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use vortex_array::scalar::PValue;
3232
use vortex_array::search_sorted::SearchSorted;
3333
use vortex_array::search_sorted::SearchSortedSide;
3434
use vortex_array::serde::ArrayChildren;
35+
use vortex_array::smallvec::smallvec;
3536
use vortex_array::validity::Validity;
3637
use vortex_array::vtable::VTable;
3738
use vortex_array::vtable::ValidityVTable;
@@ -154,7 +155,7 @@ impl VTable for RunEnd {
154155

155156
let values = children.get(1, dtype, runs)?;
156157
let offset = usize::try_from(metadata.offset).vortex_expect("Offset must be a valid usize");
157-
let slots = vec![Some(ends), Some(values)];
158+
let slots = smallvec![Some(ends), Some(values)];
158159
let data = RunEndData::new(offset);
159160
Ok(ArrayParts::new(self.clone(), dtype.clone(), len, data).with_slots(slots))
160161
}
@@ -258,7 +259,7 @@ impl RunEnd {
258259
length: usize,
259260
) -> RunEndArray {
260261
let dtype = values.dtype().clone();
261-
let slots = vec![Some(ends), Some(values)];
262+
let slots = smallvec![Some(ends), Some(values)];
262263
let data = unsafe { RunEndData::new_unchecked(offset) };
263264
unsafe {
264265
Array::from_parts_unchecked(
@@ -276,7 +277,7 @@ impl RunEnd {
276277
let len = RunEndData::logical_len_from_ends(&ends, ctx)?;
277278
RunEndData::validate_parts(&ends, &values, 0, len, ctx)?;
278279
let dtype = values.dtype().clone();
279-
let slots = vec![Some(ends), Some(values)];
280+
let slots = smallvec![Some(ends), Some(values)];
280281
let data = RunEndData::new(0);
281282
Array::try_from_parts(ArrayParts::new(RunEnd, dtype, len, data).with_slots(slots))
282283
}
@@ -291,7 +292,7 @@ impl RunEnd {
291292
) -> VortexResult<RunEndArray> {
292293
RunEndData::validate_parts(&ends, &values, offset, length, ctx)?;
293294
let dtype = values.dtype().clone();
294-
let slots = vec![Some(ends), Some(values)];
295+
let slots = smallvec![Some(ends), Some(values)];
295296
let data = RunEndData::new(offset);
296297
Array::try_from_parts(ArrayParts::new(RunEnd, dtype, length, data).with_slots(slots))
297298
}
@@ -308,7 +309,7 @@ impl RunEnd {
308309
let ends = ends.into_array();
309310
let len = array.len();
310311
let dtype = values.dtype().clone();
311-
let slots = vec![Some(ends), Some(values)];
312+
let slots = smallvec![Some(ends), Some(values)];
312313
let data = unsafe { RunEndData::new_unchecked(0) };
313314
Array::try_from_parts(ArrayParts::new(RunEnd, dtype, len, data).with_slots(slots))
314315
} else {

0 commit comments

Comments
 (0)