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

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jorge Leitao <[email protected]>
  • Loading branch information
ritchie46 and jorgecarleitao authored Sep 23, 2021
1 parent 189b424 commit 1a1425d
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<O: Offset> BinaryArray<O> {
/// # Implementation
/// This function is `O(1)`: all data will be shared between both arrays.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
.validity
Expand Down
2 changes: 1 addition & 1 deletion src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl BooleanArray {
/// # Implementation
/// This operation is `O(1)` as it amounts to increase two ref counts.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
#[inline]
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
Expand Down
4 changes: 3 additions & 1 deletion src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ impl<K: DictionaryKey> DictionaryArray<K> {
}

/// Creates a new [`DictionaryArray`] by slicing the existing [`DictionaryArray`].
/// # Safety
/// Safe iff `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
Self {
data_type: self.data_type.clone(),
Expand Down Expand Up @@ -162,7 +164,7 @@ impl<K: DictionaryKey> Array for DictionaryArray<K> {
Box::new(self.slice(offset, length))
}
unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
Box::new(self.slice_unchecked(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl FixedSizeBinaryArray {
/// # Implementation
/// This operation is `O(1)` as it amounts to increase 3 ref counts.
/// # Panics
/// panics iff `offset + length >= self.len()`
/// panics iff `offset + length > self.len()`
pub fn slice(&self, offset: usize, length: usize) -> Self {
assert!(
offset + length <= self.len(),
Expand All @@ -64,7 +64,7 @@ impl FixedSizeBinaryArray {
/// # Implementation
/// This operation is `O(1)` as it amounts to increase 3 ref counts.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
.validity
Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl FixedSizeListArray {
/// # Implementation
/// This operation is `O(1)`.
/// # Panics
/// panics iff `offset + length >= self.len()`
/// panics iff `offset + length > self.len()`
pub fn slice(&self, offset: usize, length: usize) -> Self {
assert!(
offset + length <= self.len(),
Expand All @@ -77,7 +77,7 @@ impl FixedSizeListArray {
/// # Implementation
/// This operation is `O(1)`.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
.validity
Expand Down
6 changes: 3 additions & 3 deletions src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// This operation is `O(1)` over `len`, as it amounts to increase two ref counts
/// and moving the struct to the heap.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`
/// The caller must ensure that `offset + length <=| self.len()`
unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Box<dyn Array>;

/// Sets the validity bitmap on this [`Array`].
Expand Down Expand Up @@ -434,8 +434,8 @@ fn display_fmt<T: std::fmt::Display, I: IntoIterator<Item = Option<T>>>(

/// Trait that list arrays implement for the purposes of DRY.
pub trait IterableListArray: Array {
// # Safety:
// The caller must ensure that `i < self.len()`
/// # Safety:
/// The caller must ensure that `i < self.len()`
unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array>;
}

Expand Down
2 changes: 1 addition & 1 deletion src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<T: NativeType> PrimitiveArray<T> {
/// # Implementation
/// This operation is `O(1)` as it amounts to increase two ref counts.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
#[inline]
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
Expand Down
2 changes: 1 addition & 1 deletion src/array/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl StructArray {
/// # Implementation
/// This operation is `O(F)` where `F` is the number of fields.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
.validity
Expand Down
2 changes: 1 addition & 1 deletion src/array/union/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl UnionArray {
/// # Implementation
/// This operation is `O(F)` where `F` is the number of fields.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
#[inline]
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<O: Offset> Utf8Array<O> {
/// # Implementation
/// This operation is `O(1)` as it amounts to essentially increase two ref counts.
/// # Safety
/// The caller must ensure that `offset + length < self.len()`.
/// The caller must ensure that `offset + length <= self.len()`.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Self {
let validity = self
.validity
Expand Down
2 changes: 1 addition & 1 deletion src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Bitmap {

/// Slices `self`, offseting by `offset` and truncating up to `length` bits.
/// # Safety
/// The caller must ensure that `self.offset + offset + length <= self.bytes.len() * 8`
/// The caller must ensure that `self.offset + offset + length <= self.len()`
#[inline]
pub unsafe fn slice_unchecked(mut self, offset: usize, length: usize) -> Self {
self.offset += offset;
Expand Down
5 changes: 2 additions & 3 deletions src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ impl<T: NativeType> Buffer<T> {
offset + length <= self.len(),
"the offset of the new Buffer cannot exceed the existing length"
);
// Safety:
// we just check bounds
// Safety: we just checked bounds
unsafe { self.slice_unchecked(offset, length) }
}

/// Returns a new [Buffer] that is a slice of this buffer starting at `offset`.
/// Doing so allows the same memory region to be shared between buffers.
/// # Safety
/// The caller must ensure `offset + length < self.len()`
/// The caller must ensure `offset + length <= self.len()`
#[inline]
pub unsafe fn slice_unchecked(mut self, offset: usize, length: usize) -> Self {
self.offset += offset;
Expand Down

0 comments on commit 1a1425d

Please sign in to comment.