From 1e96864d3fd22f28f54a92f53d59f4ef3135f2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kami=C5=84ski?= Date: Tue, 2 Mar 2021 13:11:05 +0100 Subject: [PATCH] Version 0.12.3 --- Cargo.toml | 2 +- src/impls.rs | 19 ++++++++++++++----- src/lib.rs | 2 ++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bfc8037634..62231eba6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "generic-array" -version = "0.12.0" +version = "0.12.3" authors = [ "Bartłomiej Kamiński ", "Aaron Trent " ] description = "Generic types implementing functionality of arrays" diff --git a/src/impls.rs b/src/impls.rs index 58a1b1fb16..ea5a3c4c90 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -21,7 +21,7 @@ where N: ArrayLength, { fn clone(&self) -> GenericArray { - self.map(|x| x.clone()) + self.map(Clone::clone) } } @@ -77,6 +77,7 @@ impl Borrow<[T]> for GenericArray where N: ArrayLength, { + #[inline(always)] fn borrow(&self) -> &[T] { &self[..] } @@ -86,6 +87,7 @@ impl BorrowMut<[T]> for GenericArray where N: ArrayLength, { + #[inline(always)] fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } @@ -95,6 +97,7 @@ impl AsRef<[T]> for GenericArray where N: ArrayLength, { + #[inline(always)] fn as_ref(&self) -> &[T] { &self[..] } @@ -104,6 +107,7 @@ impl AsMut<[T]> for GenericArray where N: ArrayLength, { + #[inline(always)] fn as_mut(&mut self) -> &mut [T] { &mut self[..] } @@ -125,11 +129,16 @@ macro_rules! impl_from { ($($n: expr => $ty: ty),*) => { $( impl From<[T; $n]> for GenericArray { + #[inline(always)] fn from(arr: [T; $n]) -> Self { - use core::mem::{forget, transmute_copy}; - let x = unsafe { transmute_copy(&arr) }; - forget(arr); - x + unsafe { $crate::transmute(arr) } + } + } + + impl Into<[T; $n]> for GenericArray { + #[inline(always)] + fn into(self) -> [T; $n] { + unsafe { $crate::transmute(self) } } } )* diff --git a/src/lib.rs b/src/lib.rs index 966015185a..e98e8fd58b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,6 +151,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()) } } @@ -160,6 +161,7 @@ impl DerefMut for GenericArray where N: ArrayLength, { + #[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()) } }