Skip to content

Commit 03d6ef7

Browse files
committed
Remove VTable::child; derive children from slots at the call sites
Every encoding used the default "idx-th non-None slot" definition, so the trait method was not a real customization point. Inline that definition into the DynArrayData children/nth_child/named_children implementations and drop the method from the vtable. Signed-off-by: "Joe Isaacs" <joe.isaacs@live.co.uk> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XbjnDVZQ9KqXgAAhxy9g7D
1 parent f06bbdc commit 03d6ef7

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

vortex-array/src/array/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
268268
}
269269

270270
fn children(&self, this: &ArrayRef) -> Vec<ArrayRef> {
271-
let view = unsafe { ArrayView::new_unchecked(this, &self.data) };
272-
(0..V::nchildren(view)).map(|i| V::child(view, i)).collect()
271+
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
272+
view.slots().iter().filter_map(|s| s.clone()).collect()
273273
}
274274

275275
fn nchildren(&self, this: &ArrayRef) -> usize {
@@ -278,8 +278,12 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
278278
}
279279

280280
fn nth_child(&self, this: &ArrayRef, idx: usize) -> Option<ArrayRef> {
281-
let view = unsafe { ArrayView::new_unchecked(this, &self.data) };
282-
(idx < V::nchildren(view)).then(|| V::child(view, idx))
281+
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
282+
view.slots()
283+
.iter()
284+
.filter_map(|s| s.as_ref())
285+
.nth(idx)
286+
.cloned()
283287
}
284288

285289
fn children_names(&self, this: &ArrayRef) -> Vec<String> {
@@ -290,9 +294,12 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
290294
}
291295

292296
fn named_children(&self, this: &ArrayRef) -> Vec<(String, ArrayRef)> {
293-
let view = unsafe { ArrayView::new_unchecked(this, &self.data) };
294-
(0..V::nchildren(view))
295-
.map(|i| (V::child_name(view, i), V::child(view, i)))
297+
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
298+
view.slots()
299+
.iter()
300+
.filter_map(|s| s.as_ref())
301+
.enumerate()
302+
.map(|(i, child)| (V::child_name(view, i), child.clone()))
296303
.collect()
297304
}
298305

vortex-array/src/array/vtable/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,6 @@ pub trait VTable: 'static + Clone + Sized + Send + Sync + Debug {
122122
array.slots().iter().filter(|s| s.is_some()).count()
123123
}
124124

125-
/// Returns the child at the given index.
126-
///
127-
/// The default returns the `idx`-th non-None slot.
128-
///
129-
/// # Panics
130-
/// Panics if `idx >= nchildren(array)`.
131-
fn child(array: ArrayView<'_, Self>, idx: usize) -> ArrayRef {
132-
array
133-
.slots()
134-
.iter()
135-
.filter_map(|s| s.clone())
136-
.nth(idx)
137-
.vortex_expect("child index out of bounds")
138-
}
139-
140125
/// Returns the name of the child at the given index.
141126
///
142127
/// The default returns the slot name of the `idx`-th non-None slot.

0 commit comments

Comments
 (0)