From 93e587b81791bdd943117b19ade708c9f7193325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 4 May 2022 17:32:42 +0200 Subject: [PATCH] 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. --- library/core/src/slice/iter.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 98dd1521d0e..415ed6203f4 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -127,6 +127,7 @@ pub(super) fn new(slice: &'a [T]) -> Self { /// ``` #[must_use] #[stable(feature = "iter_to_slice", since = "1.4.0")] + #[inline] pub fn as_slice(&self) -> &'a [T] { self.make_slice() } @@ -146,6 +147,7 @@ fn is_sorted_by(self, mut compare: F) -> bool #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Iter<'_, T> { + #[inline] fn clone(&self) -> Self { Iter { ptr: self.ptr, end: self.end, _marker: self._marker } } @@ -153,6 +155,7 @@ fn clone(&self) -> Self { #[stable(feature = "slice_iter_as_ref", since = "1.13.0")] impl AsRef<[T]> for Iter<'_, T> { + #[inline] fn as_ref(&self) -> &[T] { self.as_slice() } @@ -303,6 +306,7 @@ pub fn into_slice(self) -> &'a mut [T] { /// ``` #[must_use] #[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")] + #[inline] pub fn as_slice(&self) -> &[T] { self.make_slice() } @@ -310,6 +314,7 @@ pub fn as_slice(&self) -> &[T] { #[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")] impl AsRef<[T]> for IterMut<'_, T> { + #[inline] fn as_ref(&self) -> &[T] { self.as_slice() }