diff --git a/src/array/binary/mod.rs b/src/array/binary/mod.rs index 67908f2e810..cbcb5d78e98 100644 --- a/src/array/binary/mod.rs +++ b/src/array/binary/mod.rs @@ -101,7 +101,7 @@ impl BinaryArray { /// # 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 diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 977760dc8f2..fc0c397bbde 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -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 diff --git a/src/array/dictionary/mod.rs b/src/array/dictionary/mod.rs index a9e02edffec..8d4385c2888 100644 --- a/src/array/dictionary/mod.rs +++ b/src/array/dictionary/mod.rs @@ -86,6 +86,8 @@ impl DictionaryArray { } /// 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(), @@ -162,7 +164,7 @@ impl Array for DictionaryArray { Box::new(self.slice(offset, length)) } unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> Box { - Box::new(self.slice(offset, length)) + Box::new(self.slice_unchecked(offset, length)) } fn with_validity(&self, validity: Option) -> Box { Box::new(self.with_validity(validity)) diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index dab08e2ca71..2f0d38b0858 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -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(), @@ -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 diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index c92d0de8d73..402067867ff 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -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(), @@ -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 diff --git a/src/array/mod.rs b/src/array/mod.rs index 8397b030ebd..c9f5e325573 100644 --- a/src/array/mod.rs +++ b/src/array/mod.rs @@ -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; /// Sets the validity bitmap on this [`Array`]. @@ -434,8 +434,8 @@ fn display_fmt>>( /// 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; } diff --git a/src/array/primitive/mod.rs b/src/array/primitive/mod.rs index 980577bed77..9272e04a326 100644 --- a/src/array/primitive/mod.rs +++ b/src/array/primitive/mod.rs @@ -97,7 +97,7 @@ impl PrimitiveArray { /// # 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 diff --git a/src/array/struct_.rs b/src/array/struct_.rs index 18818f7d0c6..7f8eccdcfca 100644 --- a/src/array/struct_.rs +++ b/src/array/struct_.rs @@ -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 diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs index 52b98552fd9..de78c2762de 100644 --- a/src/array/union/mod.rs +++ b/src/array/union/mod.rs @@ -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 { diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index ab1819e4359..5f84eab7716 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -175,7 +175,7 @@ impl Utf8Array { /// # 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 diff --git a/src/bitmap/immutable.rs b/src/bitmap/immutable.rs index b6d0df82e26..6389c078d36 100644 --- a/src/bitmap/immutable.rs +++ b/src/bitmap/immutable.rs @@ -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; diff --git a/src/buffer/immutable.rs b/src/buffer/immutable.rs index 948bff115ed..63fe9260f89 100644 --- a/src/buffer/immutable.rs +++ b/src/buffer/immutable.rs @@ -91,15 +91,14 @@ impl Buffer { 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;