Skip to content

Commit 0265a3e

Browse files
committed
Auto merge of #96711 - emilio:inline-slice-clone, r=nikic
slice: #[inline] a couple iterator methods. The one I care about and actually saw in the wild not getting inlined is clone(). We ended up doing a whole function call for something that just copies two pointers. I ended up marking as_slice / as_ref as well because make_slice is inline(always) itself, and is also the kind of think that can kill performance in hot loops if you expect it to get inlined. But happy to undo those.
2 parents 691aeaa + 93e587b commit 0265a3e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: library/core/src/slice/iter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl<'a, T> Iter<'a, T> {
124124
/// ```
125125
#[must_use]
126126
#[stable(feature = "iter_to_slice", since = "1.4.0")]
127+
#[inline]
127128
pub fn as_slice(&self) -> &'a [T] {
128129
self.make_slice()
129130
}
@@ -143,13 +144,15 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, {
143144

144145
#[stable(feature = "rust1", since = "1.0.0")]
145146
impl<T> Clone for Iter<'_, T> {
147+
#[inline]
146148
fn clone(&self) -> Self {
147149
Iter { ptr: self.ptr, end: self.end, _marker: self._marker }
148150
}
149151
}
150152

151153
#[stable(feature = "slice_iter_as_ref", since = "1.13.0")]
152154
impl<T> AsRef<[T]> for Iter<'_, T> {
155+
#[inline]
153156
fn as_ref(&self) -> &[T] {
154157
self.as_slice()
155158
}
@@ -297,6 +300,7 @@ impl<'a, T> IterMut<'a, T> {
297300
/// ```
298301
#[must_use]
299302
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
303+
#[inline]
300304
pub fn as_slice(&self) -> &[T] {
301305
self.make_slice()
302306
}
@@ -345,6 +349,7 @@ impl<'a, T> IterMut<'a, T> {
345349

346350
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
347351
impl<T> AsRef<[T]> for IterMut<'_, T> {
352+
#[inline]
348353
fn as_ref(&self) -> &[T] {
349354
self.as_slice()
350355
}

0 commit comments

Comments
 (0)