Skip to content

Commit 93e587b

Browse files
committed
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.
1 parent 364bf39 commit 93e587b

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
@@ -127,6 +127,7 @@ impl<'a, T> Iter<'a, T> {
127127
/// ```
128128
#[must_use]
129129
#[stable(feature = "iter_to_slice", since = "1.4.0")]
130+
#[inline]
130131
pub fn as_slice(&self) -> &'a [T] {
131132
self.make_slice()
132133
}
@@ -146,13 +147,15 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, {
146147

147148
#[stable(feature = "rust1", since = "1.0.0")]
148149
impl<T> Clone for Iter<'_, T> {
150+
#[inline]
149151
fn clone(&self) -> Self {
150152
Iter { ptr: self.ptr, end: self.end, _marker: self._marker }
151153
}
152154
}
153155

154156
#[stable(feature = "slice_iter_as_ref", since = "1.13.0")]
155157
impl<T> AsRef<[T]> for Iter<'_, T> {
158+
#[inline]
156159
fn as_ref(&self) -> &[T] {
157160
self.as_slice()
158161
}
@@ -303,13 +306,15 @@ impl<'a, T> IterMut<'a, T> {
303306
/// ```
304307
#[must_use]
305308
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
309+
#[inline]
306310
pub fn as_slice(&self) -> &[T] {
307311
self.make_slice()
308312
}
309313
}
310314

311315
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
312316
impl<T> AsRef<[T]> for IterMut<'_, T> {
317+
#[inline]
313318
fn as_ref(&self) -> &[T] {
314319
self.as_slice()
315320
}

0 commit comments

Comments
 (0)