Skip to content

Commit f4cf82d

Browse files
committed
#[inline(always)] on forwarding slice/vec methods
1 parent 3773740 commit f4cf82d

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

library/alloc/src/vec/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl<T, A: Allocator> Vec<T, A> {
775775
/// let vec: Vec<i32> = Vec::with_capacity(10);
776776
/// assert_eq!(vec.capacity(), 10);
777777
/// ```
778-
#[inline]
778+
#[inline(always)]
779779
#[stable(feature = "rust1", since = "1.0.0")]
780780
pub fn capacity(&self) -> usize {
781781
self.buf.capacity()
@@ -1078,7 +1078,7 @@ impl<T, A: Allocator> Vec<T, A> {
10781078
/// let buffer = vec![1, 2, 3, 5, 8];
10791079
/// io::sink().write(buffer.as_slice()).unwrap();
10801080
/// ```
1081-
#[inline]
1081+
#[inline(always)]
10821082
#[stable(feature = "vec_as_slice", since = "1.7.0")]
10831083
pub fn as_slice(&self) -> &[T] {
10841084
self
@@ -1095,7 +1095,7 @@ impl<T, A: Allocator> Vec<T, A> {
10951095
/// let mut buffer = vec![0; 3];
10961096
/// io::repeat(0b101).read_exact(buffer.as_mut_slice()).unwrap();
10971097
/// ```
1098-
#[inline]
1098+
#[inline(always)]
10991099
#[stable(feature = "vec_as_slice", since = "1.7.0")]
11001100
pub fn as_mut_slice(&mut self) -> &mut [T] {
11011101
self
@@ -1820,7 +1820,7 @@ impl<T, A: Allocator> Vec<T, A> {
18201820
/// assert_eq!(a.len(), 3);
18211821
/// ```
18221822
#[doc(alias = "length")]
1823-
#[inline]
1823+
#[inline(always)]
18241824
#[stable(feature = "rust1", since = "1.0.0")]
18251825
pub fn len(&self) -> usize {
18261826
self.len
@@ -2422,7 +2422,7 @@ impl<T: Hash, A: Allocator> Hash for Vec<T, A> {
24222422
impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> {
24232423
type Output = I::Output;
24242424

2425-
#[inline]
2425+
#[inline(always)]
24262426
fn index(&self, index: I) -> &Self::Output {
24272427
Index::index(&**self, index)
24282428
}
@@ -2434,7 +2434,7 @@ impl<T, I: SliceIndex<[T]>, A: Allocator> Index<I> for Vec<T, A> {
24342434
label = "vector indices are of type `usize` or ranges of `usize`"
24352435
)]
24362436
impl<T, I: SliceIndex<[T]>, A: Allocator> IndexMut<I> for Vec<T, A> {
2437-
#[inline]
2437+
#[inline(always)]
24382438
fn index_mut(&mut self, index: I) -> &mut Self::Output {
24392439
IndexMut::index_mut(&mut **self, index)
24402440
}
@@ -2496,6 +2496,7 @@ impl<'a, T, A: Allocator> IntoIterator for &'a Vec<T, A> {
24962496
type Item = &'a T;
24972497
type IntoIter = slice::Iter<'a, T>;
24982498

2499+
#[inline(always)]
24992500
fn into_iter(self) -> slice::Iter<'a, T> {
25002501
self.iter()
25012502
}
@@ -2506,6 +2507,7 @@ impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec<T, A> {
25062507
type Item = &'a mut T;
25072508
type IntoIter = slice::IterMut<'a, T>;
25082509

2510+
#[inline(always)]
25092511
fn into_iter(self) -> slice::IterMut<'a, T> {
25102512
self.iter_mut()
25112513
}

library/core/src/iter/range.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
107107
///
108108
/// * `Step::forward_unchecked(a, n)` is equivalent to `Step::forward(a, n)`
109109
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
110+
#[inline(always)]
110111
unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
111112
Step::forward(start, count)
112113
}
@@ -179,6 +180,7 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
179180
///
180181
/// * `Step::backward_unchecked(a, n)` is equivalent to `Step::backward(a, n)`
181182
#[unstable(feature = "step_trait_ext", reason = "recently added", issue = "42168")]
183+
#[inline(always)]
182184
unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
183185
Step::backward(start, count)
184186
}
@@ -187,13 +189,13 @@ pub unsafe trait Step: Clone + PartialOrd + Sized {
187189
// These are still macro-generated because the integer literals resolve to different types.
188190
macro_rules! step_identical_methods {
189191
() => {
190-
#[inline]
192+
#[inline(always)]
191193
unsafe fn forward_unchecked(start: Self, n: usize) -> Self {
192194
// SAFETY: the caller has to guarantee that `start + n` doesn't overflow.
193195
unsafe { start.unchecked_add(n as Self) }
194196
}
195197

196-
#[inline]
198+
#[inline(always)]
197199
unsafe fn backward_unchecked(start: Self, n: usize) -> Self {
198200
// SAFETY: the caller has to guarantee that `start - n` doesn't overflow.
199201
unsafe { start.unchecked_sub(n as Self) }
@@ -345,12 +347,12 @@ macro_rules! step_integer_impls {
345347
}
346348
}
347349

348-
#[inline]
350+
#[inline(always)]
349351
fn forward_checked(start: Self, n: usize) -> Option<Self> {
350352
start.checked_add(n as Self)
351353
}
352354

353-
#[inline]
355+
#[inline(always)]
354356
fn backward_checked(start: Self, n: usize) -> Option<Self> {
355357
start.checked_sub(n as Self)
356358
}
@@ -375,12 +377,12 @@ macro_rules! step_integer_impls {
375377
}
376378
}
377379

378-
#[inline]
380+
#[inline(always)]
379381
fn forward_checked(start: Self, n: usize) -> Option<Self> {
380382
start.checked_add(n as Self)
381383
}
382384

383-
#[inline]
385+
#[inline(always)]
384386
fn backward_checked(start: Self, n: usize) -> Option<Self> {
385387
start.checked_sub(n as Self)
386388
}
@@ -551,17 +553,17 @@ impl<A: Step> Iterator for ops::Range<A> {
551553
None
552554
}
553555

554-
#[inline]
556+
#[inline(always)]
555557
fn last(mut self) -> Option<A> {
556558
self.next_back()
557559
}
558560

559-
#[inline]
561+
#[inline(always)]
560562
fn min(mut self) -> Option<A> {
561563
self.next()
562564
}
563565

564-
#[inline]
566+
#[inline(always)]
565567
fn max(mut self) -> Option<A> {
566568
self.next_back()
567569
}
@@ -671,7 +673,7 @@ impl<A: Step> Iterator for ops::RangeFrom<A> {
671673
Some(mem::replace(&mut self.start, n))
672674
}
673675

674-
#[inline]
676+
#[inline(always)]
675677
fn size_hint(&self) -> (usize, Option<usize>) {
676678
(usize::MAX, None)
677679
}
@@ -793,17 +795,17 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
793795
self.try_fold(init, ok(f)).unwrap()
794796
}
795797

796-
#[inline]
798+
#[inline(always)]
797799
fn last(mut self) -> Option<A> {
798800
self.next_back()
799801
}
800802

801-
#[inline]
803+
#[inline(always)]
802804
fn min(mut self) -> Option<A> {
803805
self.next()
804806
}
805807

806-
#[inline]
808+
#[inline(always)]
807809
fn max(mut self) -> Option<A> {
808810
self.next_back()
809811
}

library/core/src/slice/iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl<'a, T> IntoIterator for &'a [T] {
2121
type Item = &'a T;
2222
type IntoIter = Iter<'a, T>;
2323

24+
#[inline(always)]
2425
fn into_iter(self) -> Iter<'a, T> {
2526
self.iter()
2627
}
@@ -31,6 +32,7 @@ impl<'a, T> IntoIterator for &'a mut [T] {
3132
type Item = &'a mut T;
3233
type IntoIter = IterMut<'a, T>;
3334

35+
#[inline(always)]
3436
fn into_iter(self) -> IterMut<'a, T> {
3537
self.iter_mut()
3638
}

library/core/src/slice/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<T> [T] {
299299
/// assert_eq!(None, v.get(0..4));
300300
/// ```
301301
#[stable(feature = "rust1", since = "1.0.0")]
302-
#[inline]
302+
#[inline(always)]
303303
pub fn get<I>(&self, index: I) -> Option<&I::Output>
304304
where
305305
I: SliceIndex<Self>,
@@ -323,7 +323,7 @@ impl<T> [T] {
323323
/// assert_eq!(x, &[0, 42, 2]);
324324
/// ```
325325
#[stable(feature = "rust1", since = "1.0.0")]
326-
#[inline]
326+
#[inline(always)]
327327
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
328328
where
329329
I: SliceIndex<Self>,
@@ -354,7 +354,7 @@ impl<T> [T] {
354354
/// }
355355
/// ```
356356
#[stable(feature = "rust1", since = "1.0.0")]
357-
#[inline]
357+
#[inline(always)]
358358
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
359359
where
360360
I: SliceIndex<Self>,
@@ -390,7 +390,7 @@ impl<T> [T] {
390390
/// assert_eq!(x, &[1, 13, 4]);
391391
/// ```
392392
#[stable(feature = "rust1", since = "1.0.0")]
393-
#[inline]
393+
#[inline(always)]
394394
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
395395
where
396396
I: SliceIndex<Self>,
@@ -429,7 +429,7 @@ impl<T> [T] {
429429
/// [`as_mut_ptr`]: slice::as_mut_ptr
430430
#[stable(feature = "rust1", since = "1.0.0")]
431431
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
432-
#[inline]
432+
#[inline(always)]
433433
pub const fn as_ptr(&self) -> *const T {
434434
self as *const [T] as *const T
435435
}
@@ -457,7 +457,7 @@ impl<T> [T] {
457457
/// ```
458458
#[stable(feature = "rust1", since = "1.0.0")]
459459
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
460-
#[inline]
460+
#[inline(always)]
461461
pub const fn as_mut_ptr(&mut self) -> *mut T {
462462
self as *mut [T] as *mut T
463463
}
@@ -702,7 +702,7 @@ impl<T> [T] {
702702
/// assert_eq!(iterator.next(), None);
703703
/// ```
704704
#[stable(feature = "rust1", since = "1.0.0")]
705-
#[inline]
705+
#[inline(always)]
706706
pub fn iter(&self) -> Iter<'_, T> {
707707
Iter::new(self)
708708
}
@@ -719,7 +719,7 @@ impl<T> [T] {
719719
/// assert_eq!(x, &[3, 4, 6]);
720720
/// ```
721721
#[stable(feature = "rust1", since = "1.0.0")]
722-
#[inline]
722+
#[inline(always)]
723723
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
724724
IterMut::new(self)
725725
}
@@ -3544,7 +3544,7 @@ pub trait SlicePattern {
35443544
impl<T> SlicePattern for [T] {
35453545
type Item = T;
35463546

3547-
#[inline]
3547+
#[inline(always)]
35483548
fn as_slice(&self) -> &[Self::Item] {
35493549
self
35503550
}
@@ -3554,7 +3554,7 @@ impl<T> SlicePattern for [T] {
35543554
impl<T, const N: usize> SlicePattern for [T; N] {
35553555
type Item = T;
35563556

3557-
#[inline]
3557+
#[inline(always)]
35583558
fn as_slice(&self) -> &[Self::Item] {
35593559
self
35603560
}

0 commit comments

Comments
 (0)