From fea8b61daed97ede1cbce928e3a9af4c1d033953 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 2 Oct 2026 04:08:52 +0100 Subject: [PATCH 1/3] Write scatter_indices bits without per-element capacity checks --- src/enums/array.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/enums/array.rs b/src/enums/array.rs index 8b9b7f1..8e18196 100644 --- a/src/enums/array.rs +++ b/src/enums/array.rs @@ -1507,14 +1507,24 @@ impl Array { match $src_mask { Some(sm) => { let mask = $dst_mask.get_or_insert_with(|| Bitmask::new_set_all(dst_len, true)); + mask.ensure_capacity(dst_len); for (&d, &s) in dst_idx.iter().zip(src_idx) { - mask.set(d, sm.get(offset + s)); + // Safety: the bounds checks above put every `d` + // inside this array and every `s` inside the + // window, `ensure_capacity` sizes this mask to the + // array, and the source mask spans its backing + // array. + unsafe { mask.set_unchecked(d, sm.get_unchecked(offset + s)) }; } } None => { if let Some(mask) = $dst_mask.as_mut() { + mask.ensure_capacity(dst_len); for &d in dst_idx { - mask.set(d, true); + // Safety: the bounds check above puts every + // `d` inside this array, and `ensure_capacity` + // sizes this mask to the array. + unsafe { mask.set_unchecked(d, true) }; } } } @@ -1645,8 +1655,12 @@ impl Array { }, (Array::BooleanArray(d), Array::BooleanArray(s)) => { let dst = Arc::make_mut(d); + dst.data.ensure_capacity(dst_len); for (&di, &si) in dst_idx.iter().zip(src_idx) { - dst.data.set(di, s.data.get(offset + si)); + // Safety: the bounds checks above put every `di` inside + // this array and every `si` inside the window, and + // `ensure_capacity` sizes the value bits to the array. + unsafe { dst.data.set_unchecked(di, s.data.get_unchecked(offset + si)) }; } scatter_mask!(dst.null_mask, s.null_mask.as_ref()); } From d24311b42a916f3d03c7fe2d5d8db33241d63fd7 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 2 Oct 2026 04:30:07 +0100 Subject: [PATCH 2/3] Update array.rs --- src/enums/array.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/enums/array.rs b/src/enums/array.rs index 8e18196..34ea968 100644 --- a/src/enums/array.rs +++ b/src/enums/array.rs @@ -1509,11 +1509,11 @@ impl Array { let mask = $dst_mask.get_or_insert_with(|| Bitmask::new_set_all(dst_len, true)); mask.ensure_capacity(dst_len); for (&d, &s) in dst_idx.iter().zip(src_idx) { - // Safety: the bounds checks above put every `d` - // inside this array and every `s` inside the - // window, `ensure_capacity` sizes this mask to the - // array, and the source mask spans its backing - // array. + // Safety: + // - the bounds checks above ensures every `d` + // is inside this array and every `s` inside the window + // - `ensure_capacity` sizes this mask to the array + // - the source mask spans its backing array. unsafe { mask.set_unchecked(d, sm.get_unchecked(offset + s)) }; } } @@ -1521,9 +1521,9 @@ impl Array { if let Some(mask) = $dst_mask.as_mut() { mask.ensure_capacity(dst_len); for &d in dst_idx { - // Safety: the bounds check above puts every - // `d` inside this array, and `ensure_capacity` - // sizes this mask to the array. + // Safety: + // - the bounds check above ensures every `d` is inside this array + // - `ensure_capacity` sizes this mask to the array. unsafe { mask.set_unchecked(d, true) }; } } From a0adcbf039bf5bc4be265d14d3b3d341827d6d8e Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Fri, 2 Oct 2026 04:31:48 +0100 Subject: [PATCH 3/3] Update array.rs --- src/enums/array.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/enums/array.rs b/src/enums/array.rs index 34ea968..5fac2e3 100644 --- a/src/enums/array.rs +++ b/src/enums/array.rs @@ -1657,9 +1657,10 @@ impl Array { let dst = Arc::make_mut(d); dst.data.ensure_capacity(dst_len); for (&di, &si) in dst_idx.iter().zip(src_idx) { - // Safety: the bounds checks above put every `di` inside - // this array and every `si` inside the window, and - // `ensure_capacity` sizes the value bits to the array. + // Safety: + // - the bounds checks above mean every `di` is inside + // this array and every `si` inside the window + // - `ensure_capacity` sizes the value bits to the array. unsafe { dst.data.set_unchecked(di, s.data.get_unchecked(offset + si)) }; } scatter_mask!(dst.null_mask, s.null_mask.as_ref());