From 7a25123845778fdaa715815cc9ec917a67c35dbd Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 18 Oct 2020 15:38:32 +0200 Subject: [PATCH 1/3] Add #[inline] to the Utf8Error accessors. --- library/core/src/str/error.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index 427f720d68cdb..ccf7b20285cb3 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -72,6 +72,7 @@ impl Utf8Error { /// assert_eq!(1, error.valid_up_to()); /// ``` #[stable(feature = "utf8_error", since = "1.5.0")] + #[inline] pub fn valid_up_to(&self) -> usize { self.valid_up_to } @@ -92,6 +93,7 @@ impl Utf8Error { /// /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html #[stable(feature = "utf8_error_error_len", since = "1.20.0")] + #[inline] pub fn error_len(&self) -> Option { self.error_len.map(|len| len as usize) } From 76daca2791f3deeee925e449d7db51795f55121d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 18 Oct 2020 15:39:09 +0200 Subject: [PATCH 2/3] Add #[inline] to some core::str functions. Almost all these functions already had #[inline]. These were missing. --- library/core/src/str/iter.rs | 1 + library/core/src/str/mod.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index bee86df520c80..28cd350019ebf 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -326,6 +326,7 @@ unsafe impl TrustedLen for Bytes<'_> {} #[doc(hidden)] #[unstable(feature = "trusted_random_access", issue = "none")] unsafe impl TrustedRandomAccess for Bytes<'_> { + #[inline] fn may_have_side_effect() -> bool { false } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 3e18a4e70627d..5d80d2be9a4d3 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1711,6 +1711,7 @@ impl str { /// /// assert_eq!("Hello\tworld", s.trim()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a slice, \ without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] @@ -1748,6 +1749,7 @@ impl str { /// let s = " עברית "; /// assert!(Some('ע') == s.trim_start().chars().next()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] @@ -1785,6 +1787,7 @@ impl str { /// let s = " עברית "; /// assert!(Some('ת') == s.trim_end().chars().rev().next()); /// ``` + #[inline] #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] @@ -1823,6 +1826,7 @@ impl str { /// let s = " עברית"; /// assert!(Some('ע') == s.trim_left().chars().next()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated( since = "1.33.0", @@ -1864,6 +1868,7 @@ impl str { /// let s = "עברית "; /// assert!(Some('ת') == s.trim_right().chars().rev().next()); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated( since = "1.33.0", @@ -2261,6 +2266,7 @@ impl str { /// assert_eq!("GRüßE, JüRGEN ❤", s); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[inline] pub fn make_ascii_uppercase(&mut self) { // SAFETY: safe because we transmute two types with the same layout. let me = unsafe { self.as_bytes_mut() }; @@ -2287,6 +2293,7 @@ impl str { /// assert_eq!("grÜße, jÜrgen ❤", s); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[inline] pub fn make_ascii_lowercase(&mut self) { // SAFETY: safe because we transmute two types with the same layout. let me = unsafe { self.as_bytes_mut() }; From cc850ecba0641f0ec56507ee656ad9a301705c83 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 18 Oct 2020 15:39:42 +0200 Subject: [PATCH 3/3] Add #[inline] to {&str, &mut str}::default. --- library/core/src/str/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 5d80d2be9a4d3..345447a4cbb2a 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2431,6 +2431,7 @@ impl AsRef<[u8]> for str { #[stable(feature = "rust1", since = "1.0.0")] impl Default for &str { /// Creates an empty str + #[inline] fn default() -> Self { "" } @@ -2439,6 +2440,7 @@ impl Default for &str { #[stable(feature = "default_mut_str", since = "1.28.0")] impl Default for &mut str { /// Creates an empty mutable str + #[inline] fn default() -> Self { // SAFETY: The empty string is valid UTF-8. unsafe { from_utf8_unchecked_mut(&mut []) }