|
| 1 | +use std::mem; |
| 2 | +use std::mem::MaybeUninit; |
| 3 | + |
1 | 4 | use vortex_array::compute::{ |
2 | 5 | BetweenFn, BetweenOptions, FilterKernelAdapter, KernelRef, ScalarAtFn, SearchSortedFn, SliceFn, |
3 | 6 | TakeFn, between, |
@@ -45,28 +48,37 @@ fn chunked_indices<F: FnMut(usize, &[usize])>( |
45 | 48 | offset: usize, |
46 | 49 | mut chunk_fn: F, |
47 | 50 | ) { |
48 | | - let mut indices_within_chunk: Vec<usize> = Vec::with_capacity(1024); |
| 51 | + let mut indices_within_chunk = [const { MaybeUninit::<usize>::uninit() }; 1024]; |
| 52 | + let mut indices_len = 0; |
49 | 53 |
|
50 | 54 | let Some(first_idx) = indices.next() else { |
51 | 55 | return; |
52 | 56 | }; |
53 | 57 |
|
54 | 58 | let mut current_chunk_idx = (first_idx + offset) / 1024; |
55 | | - indices_within_chunk.push((first_idx + offset) % 1024); |
| 59 | + indices_within_chunk[indices_len] = MaybeUninit::new((first_idx + offset) % 1024); |
| 60 | + indices_len += 1; |
56 | 61 | for idx in indices { |
57 | 62 | let new_chunk_idx = (idx + offset) / 1024; |
58 | 63 |
|
59 | 64 | if new_chunk_idx != current_chunk_idx { |
60 | | - chunk_fn(current_chunk_idx, &indices_within_chunk); |
61 | | - indices_within_chunk.clear(); |
| 65 | + chunk_fn(current_chunk_idx, unsafe { |
| 66 | + mem::transmute::<&[MaybeUninit<usize>], &[usize]>( |
| 67 | + &indices_within_chunk[..indices_len], |
| 68 | + ) |
| 69 | + }); |
| 70 | + indices_len = 0; |
62 | 71 | } |
63 | 72 |
|
64 | 73 | current_chunk_idx = new_chunk_idx; |
65 | | - indices_within_chunk.push((idx + offset) % 1024); |
| 74 | + indices_within_chunk[indices_len] = MaybeUninit::new((idx + offset) % 1024); |
| 75 | + indices_len += 1; |
66 | 76 | } |
67 | 77 |
|
68 | | - if !indices_within_chunk.is_empty() { |
69 | | - chunk_fn(current_chunk_idx, &indices_within_chunk); |
| 78 | + if indices_len > 0 { |
| 79 | + chunk_fn(current_chunk_idx, unsafe { |
| 80 | + mem::transmute::<&[MaybeUninit<usize>], &[usize]>(&indices_within_chunk[..indices_len]) |
| 81 | + }); |
70 | 82 | } |
71 | 83 | } |
72 | 84 |
|
|
0 commit comments