Skip to content

Commit

Permalink
Force inline for *ref methods
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Jun 24, 2019
1 parent df9b680 commit a6b9e59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl<T, N> Borrow<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn borrow(&self) -> &[T] {
&self[..]
}
Expand All @@ -84,6 +85,7 @@ impl<T, N> BorrowMut<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn borrow_mut(&mut self) -> &mut [T] {
&mut self[..]
}
Expand All @@ -93,6 +95,7 @@ impl<T, N> AsRef<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn as_ref(&self) -> &[T] {
&self[..]
}
Expand All @@ -102,6 +105,7 @@ impl<T, N> AsMut<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn as_mut(&mut self) -> &mut [T] {
&mut self[..]
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ where
{
type Target = [T];

#[inline(always)]
fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self as *const Self as *const T, N::to_usize()) }
}
Expand All @@ -161,6 +162,7 @@ impl<T, N> DerefMut for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn deref_mut(&mut self) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(self as *mut Self as *mut T, N::to_usize()) }
}
Expand Down

0 comments on commit a6b9e59

Please sign in to comment.