Skip to content

Commit 9280c8d

Browse files
committed
Always inline Index methods.
1 parent 10a449d commit 9280c8d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,13 @@ impl<A, T> Aligned<A, [T]>
159159
where
160160
A: Alignment,
161161
{
162+
#[inline(always)]
162163
fn is_index_aligned(index: usize) -> bool {
163164
use core::mem::size_of;
164165

165166
(index * size_of::<T>()) % A::ALIGN == 0
166167
}
168+
#[inline(always)]
167169
fn check_start_index(index: usize) {
168170
if !Self::is_index_aligned(index) {
169171
panic!("Unaligned start index");
@@ -177,6 +179,7 @@ where
177179
{
178180
type Output = Aligned<A, [T]>;
179181

182+
#[inline(always)]
180183
fn index(&self, range: ops::RangeFrom<usize>) -> &Aligned<A, [T]> {
181184
Self::check_start_index(range.start);
182185
unsafe { &*(&self.value[range] as *const [T] as *const Aligned<A, [T]>) }
@@ -211,6 +214,7 @@ where
211214
{
212215
type Output = Aligned<A, [T]>;
213216

217+
#[inline(always)]
214218
fn index(&self, range: ops::RangeInclusive<usize>) -> &Aligned<A, [T]> {
215219
Self::check_start_index(*range.start());
216220
unsafe { &*(&self.value[range] as *const [T] as *const Aligned<A, [T]>) }
@@ -223,6 +227,7 @@ where
223227
{
224228
type Output = Aligned<A, [T]>;
225229

230+
#[inline(always)]
226231
fn index(&self, range: ops::Range<usize>) -> &Aligned<A, [T]> {
227232
Self::check_start_index(range.start);
228233
unsafe { &*(&self.value[range] as *const [T] as *const Aligned<A, [T]>) }
@@ -244,6 +249,7 @@ impl<A, T> ops::IndexMut<ops::RangeFrom<usize>> for Aligned<A, [T]>
244249
where
245250
A: Alignment,
246251
{
252+
#[inline(always)]
247253
fn index_mut(&mut self, range: ops::RangeFrom<usize>) -> &mut Aligned<A, [T]> {
248254
Self::check_start_index(range.start);
249255
unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned<A, [T]>) }
@@ -272,6 +278,7 @@ impl<A, T> ops::IndexMut<ops::RangeInclusive<usize>> for Aligned<A, [T]>
272278
where
273279
A: Alignment,
274280
{
281+
#[inline(always)]
275282
fn index_mut(&mut self, range: ops::RangeInclusive<usize>) -> &mut Aligned<A, [T]> {
276283
Self::check_start_index(*range.start());
277284
unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned<A, [T]>) }
@@ -282,6 +289,7 @@ impl<A, T> ops::IndexMut<ops::Range<usize>> for Aligned<A, [T]>
282289
where
283290
A: Alignment,
284291
{
292+
#[inline(always)]
285293
fn index_mut(&mut self, range: ops::Range<usize>) -> &mut Aligned<A, [T]> {
286294
Self::check_start_index(range.start);
287295
unsafe { &mut *(&mut self.value[range] as *mut [T] as *mut Aligned<A, [T]>) }

0 commit comments

Comments
 (0)