Skip to content

Commit cbeb009

Browse files
committed
fix
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent ec41567 commit cbeb009

16 files changed

Lines changed: 55 additions & 48 deletions

File tree

encodings/alp/src/alp/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ impl ALPArray {
478478

479479
/// Consumes the array and returns its parts.
480480
#[inline]
481-
pub fn into_parts(self) -> (ArrayRef, Exponents, Option<Patches>, DType) {
481+
pub fn into_parts(mut self) -> (ArrayRef, Exponents, Option<Patches>, DType) {
482482
let encoded = self.slots[ENCODED_SLOT]
483-
.clone()
483+
.take()
484484
.vortex_expect("ALPArray encoded slot");
485485
(encoded, self.exponents, self.patches, self.dtype)
486486
}

encodings/alp/src/alp_rd/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,12 @@ impl ALPRDArray {
496496
}
497497

498498
/// Return all the owned parts of the array
499-
pub fn into_parts(self) -> ALPRDArrayParts {
499+
pub fn into_parts(mut self) -> ALPRDArrayParts {
500500
let left_parts = self.slots[LEFT_PARTS_SLOT]
501-
.clone()
501+
.take()
502502
.vortex_expect("ALPRDArray left_parts slot");
503503
let right_parts = self.slots[RIGHT_PARTS_SLOT]
504-
.clone()
504+
.take()
505505
.vortex_expect("ALPRDArray right_parts slot");
506506
ALPRDArrayParts {
507507
dtype: self.dtype,

encodings/datetime-parts/src/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ impl DateTimePartsArray {
316316
}
317317
}
318318

319-
pub fn into_parts(self) -> DateTimePartsArrayParts {
319+
pub fn into_parts(mut self) -> DateTimePartsArrayParts {
320320
DateTimePartsArrayParts {
321321
dtype: self.dtype,
322322
days: self.slots[DAYS_SLOT]
323-
.clone()
323+
.take()
324324
.vortex_expect("DateTimePartsArray days slot"),
325325
seconds: self.slots[SECONDS_SLOT]
326-
.clone()
326+
.take()
327327
.vortex_expect("DateTimePartsArray seconds slot"),
328328
subseconds: self.slots[SUBSECONDS_SLOT]
329-
.clone()
329+
.take()
330330
.vortex_expect("DateTimePartsArray subseconds slot"),
331331
}
332332
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ impl DecimalBytePartsArray {
256256
}
257257

258258
/// If `_lower_parts` is supported check all calls use this correctly.
259-
pub fn into_parts(self) -> DecimalBytePartsArrayParts {
259+
pub fn into_parts(mut self) -> DecimalBytePartsArrayParts {
260260
DecimalBytePartsArrayParts {
261261
msp: self.slots[MSP_SLOT]
262-
.clone()
262+
.take()
263263
.vortex_expect("DecimalBytePartsArray msp slot"),
264264
dtype: self.dtype,
265265
}

encodings/runend/src/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ impl RunEndArray {
448448

449449
/// Split an `RunEndArray` into parts.
450450
#[inline]
451-
pub fn into_parts(self) -> RunEndArrayParts {
451+
pub fn into_parts(mut self) -> RunEndArrayParts {
452452
RunEndArrayParts {
453453
ends: self.slots[ENDS_SLOT]
454-
.clone()
454+
.take()
455455
.vortex_expect("RunEndArray ends slot"),
456456
values: self.slots[VALUES_SLOT]
457-
.clone()
457+
.take()
458458
.vortex_expect("RunEndArray values slot"),
459459
}
460460
}

vortex-array/public-api.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22246,7 +22246,7 @@ pub fn vortex_array::vtable::DynVTable::reduce(&self, array: &vortex_array::Arra
2224622246

2224722247
pub fn vortex_array::vtable::DynVTable::reduce_parent(&self, array: &vortex_array::ArrayRef, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2224822248

22249-
pub fn vortex_array::vtable::DynVTable::with_slots(&self, array: &vortex_array::ArrayRef, slots: alloc::vec::Vec<core::option::Option<vortex_array::ArrayRef>>) -> vortex_error::VortexResult<vortex_array::ArrayRef>
22249+
pub fn vortex_array::vtable::DynVTable::with_slots(&self, array: vortex_array::ArrayRef, slots: alloc::vec::Vec<core::option::Option<vortex_array::ArrayRef>>) -> vortex_error::VortexResult<vortex_array::ArrayRef>
2225022250

2225122251
impl<V: vortex_array::vtable::VTable> vortex_array::vtable::DynVTable for V
2225222252

@@ -22262,7 +22262,7 @@ pub fn V::reduce(&self, array: &vortex_array::ArrayRef) -> vortex_error::VortexR
2226222262

2226322263
pub fn V::reduce_parent(&self, array: &vortex_array::ArrayRef, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>
2226422264

22265-
pub fn V::with_slots(&self, array: &vortex_array::ArrayRef, slots: alloc::vec::Vec<core::option::Option<vortex_array::ArrayRef>>) -> vortex_error::VortexResult<vortex_array::ArrayRef>
22265+
pub fn V::with_slots(&self, array: vortex_array::ArrayRef, slots: alloc::vec::Vec<core::option::Option<vortex_array::ArrayRef>>) -> vortex_error::VortexResult<vortex_array::ArrayRef>
2226622266

2226722267
pub trait vortex_array::vtable::OperationsVTable<V: vortex_array::vtable::VTable>
2226822268

vortex-array/src/array/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,24 @@ impl dyn DynArray + '_ {
346346
}
347347

348348
/// Returns a new array with the slot at `slot_idx` replaced by `replacement`.
349-
pub fn with_slot(&self, slot_idx: usize, replacement: ArrayRef) -> VortexResult<ArrayRef> {
350-
let slots = self.slots();
349+
///
350+
/// Takes ownership to allow in-place mutation when the refcount is 1.
351+
pub fn with_slot(
352+
self: ArrayRef,
353+
slot_idx: usize,
354+
replacement: ArrayRef,
355+
) -> VortexResult<ArrayRef> {
356+
let nslots = self.slots().len();
351357
vortex_ensure!(
352-
slot_idx < slots.len(),
358+
slot_idx < nslots,
353359
"slot index {} out of bounds for array with {} slots",
354360
slot_idx,
355-
slots.len()
361+
nslots
356362
);
357-
let mut slots = slots.to_vec();
363+
let mut slots = self.slots().to_vec();
358364
slots[slot_idx] = Some(replacement);
359-
self.vtable().with_slots(&self.to_array(), slots)
365+
let vtable = self.vtable().clone_boxed();
366+
vtable.with_slots(self, slots)
360367
}
361368
}
362369

vortex-array/src/arrays/dict/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ impl DictArray {
123123
Ok(unsafe { Self::new_unchecked(codes, values) })
124124
}
125125

126-
pub fn into_parts(self) -> DictArrayParts {
126+
pub fn into_parts(mut self) -> DictArrayParts {
127127
DictArrayParts {
128128
codes: self.slots[CODES_SLOT]
129-
.clone()
129+
.take()
130130
.vortex_expect("DictArray codes slot"),
131131
values: self.slots[VALUES_SLOT]
132-
.clone()
132+
.take()
133133
.vortex_expect("DictArray values slot"),
134134
dtype: self.dtype,
135135
}

vortex-array/src/arrays/filter/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ impl FilterArray {
7272
}
7373

7474
/// Consume the array and return its individual components.
75-
pub fn into_parts(self) -> FilterArrayParts {
75+
pub fn into_parts(mut self) -> FilterArrayParts {
7676
FilterArrayParts {
7777
child: self.slots[CHILD_SLOT]
78-
.clone()
78+
.take()
7979
.vortex_expect("FilterArray child slot"),
8080
mask: self.mask,
8181
}

vortex-array/src/arrays/fixed_size_list/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ impl FixedSizeListArray {
172172
}
173173
}
174174

175-
pub fn into_parts(self) -> (ArrayRef, Validity, DType) {
175+
pub fn into_parts(mut self) -> (ArrayRef, Validity, DType) {
176176
(
177177
self.slots[ELEMENTS_SLOT]
178-
.clone()
178+
.take()
179179
.vortex_expect("FixedSizeListArray elements slot"),
180180
self.validity,
181181
self.dtype,

0 commit comments

Comments
 (0)