Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
add slice_unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 23, 2021
1 parent 82e4fb2 commit 12072a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 144 deletions.
141 changes: 0 additions & 141 deletions benches/filter_kernels.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/array/fixed_size_list/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::FixedSizeListArray;

impl IterableListArray for FixedSizeListArray {
unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array> {
FixedSizeListArray::value(self, i)
FixedSizeListArray::value_unchecked(self, i)
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,23 @@ impl FixedSizeListArray {
}

/// Returns the `Vec<T>` at position `i`.
/// # Panic:
/// panics iff `i >= self.len()`
#[inline]
pub fn value(&self, i: usize) -> Box<dyn Array> {
self.values
.slice(i * self.size as usize, self.size as usize)
}

/// Returns the `Vec<T>` at position `i`.
/// # Safety:
/// Caller must ensure that `i < self.len()`
#[inline]
pub unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array> {
self.values
.slice_unchecked(i * self.size as usize, self.size as usize)
}

/// Sets the validity bitmap on this [`FixedSizeListArray`].
/// # Panic
/// This function panics iff `validity.len() != self.len()`.
Expand Down
7 changes: 5 additions & 2 deletions src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ impl<O: Offset> ListArray<O> {
let offset_1 = offsets[i + 1];
let length = (offset_1 - offset).to_usize();

self.values.slice(offset.to_usize(), length)
// Safety:
// One of the invariants of the struct
// is that offsets are in bounds
unsafe { self.values.slice_unchecked(offset.to_usize(), length) }
}
}

Expand All @@ -93,7 +96,7 @@ impl<O: Offset> ListArray<O> {
let offset_1 = *self.offsets.as_ptr().add(i + 1);
let length = (offset_1 - offset).to_usize();

self.values.slice(offset.to_usize(), length)
self.values.slice_unchecked(offset.to_usize(), length)
}

/// Returns a slice of this [`ListArray`].
Expand Down

0 comments on commit 12072a1

Please sign in to comment.