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

Commit

Permalink
elide bounds check
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 2, 2022
1 parent e87b3cf commit 5ed0c43
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ impl<T: NativeType> Buffer<T> {
/// Returns the byte slice stored in this buffer
#[inline]
pub fn as_slice(&self) -> &[T] {
&self.data[self.offset..self.offset + self.length]
// Safety:
// invariant of this struct `offset + length <= data.len()`
debug_assert!(self.offset + self.length <= self.data.len());
unsafe {
self.data
.get_unchecked(self.offset..self.offset + self.length)
}
}

/// Returns a new [Buffer] that is a slice of this buffer starting at `offset`.
Expand Down

0 comments on commit 5ed0c43

Please sign in to comment.