From 9280c8d3a3514cb8a3e4872d141ff202763c2f5a Mon Sep 17 00:00:00 2001 From: Kor Nielsen Date: Thu, 13 Feb 2025 23:42:06 -0800 Subject: [PATCH 1/2] Always inline Index methods. --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0caeabc..1afb66a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,11 +159,13 @@ impl Aligned where A: Alignment, { + #[inline(always)] fn is_index_aligned(index: usize) -> bool { use core::mem::size_of; (index * size_of::()) % A::ALIGN == 0 } + #[inline(always)] fn check_start_index(index: usize) { if !Self::is_index_aligned(index) { panic!("Unaligned start index"); @@ -177,6 +179,7 @@ where { type Output = Aligned; + #[inline(always)] fn index(&self, range: ops::RangeFrom) -> &Aligned { Self::check_start_index(range.start); unsafe { &*(&self.value[range] as *const [T] as *const Aligned) } @@ -211,6 +214,7 @@ where { type Output = Aligned; + #[inline(always)] fn index(&self, range: ops::RangeInclusive) -> &Aligned { Self::check_start_index(*range.start()); unsafe { &*(&self.value[range] as *const [T] as *const Aligned) } @@ -223,6 +227,7 @@ where { type Output = Aligned; + #[inline(always)] fn index(&self, range: ops::Range) -> &Aligned { Self::check_start_index(range.start); unsafe { &*(&self.value[range] as *const [T] as *const Aligned) } @@ -244,6 +249,7 @@ impl ops::IndexMut> for Aligned where A: Alignment, { + #[inline(always)] fn index_mut(&mut self, range: ops::RangeFrom) -> &mut Aligned { Self::check_start_index(range.start); unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned) } @@ -272,6 +278,7 @@ impl ops::IndexMut> for Aligned where A: Alignment, { + #[inline(always)] fn index_mut(&mut self, range: ops::RangeInclusive) -> &mut Aligned { Self::check_start_index(*range.start()); unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned) } @@ -282,6 +289,7 @@ impl ops::IndexMut> for Aligned where A: Alignment, { + #[inline(always)] fn index_mut(&mut self, range: ops::Range) -> &mut Aligned { Self::check_start_index(range.start); unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned) } From 00818cf81d7c858bec568c63f847bf6be840100e Mon Sep 17 00:00:00 2001 From: Kor Nielsen Date: Fri, 12 Dec 2025 15:27:47 -0800 Subject: [PATCH 2/2] Support unsized types in std trait delegations. This makes it possible to use PartialEq, Debug, etc with unsized types such as `Aligned`. --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1afb66a..05f70fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,7 +398,7 @@ where } } -impl Debug for Aligned +impl Debug for Aligned where A: Alignment, T: Debug, @@ -408,7 +408,7 @@ where } } -impl Display for Aligned +impl Display for Aligned where A: Alignment, T: Display, @@ -418,7 +418,7 @@ where } } -impl PartialEq for Aligned +impl PartialEq for Aligned where A: Alignment, T: PartialEq, @@ -428,14 +428,14 @@ where } } -impl Eq for Aligned +impl Eq for Aligned where A: Alignment, T: Eq, { } -impl Hash for Aligned +impl Hash for Aligned where A: Alignment, T: Hash, @@ -445,7 +445,7 @@ where } } -impl Ord for Aligned +impl Ord for Aligned where A: Alignment, T: Ord, @@ -455,7 +455,7 @@ where } } -impl PartialOrd for Aligned +impl PartialOrd for Aligned where A: Alignment, T: PartialOrd,