From 9c3c8efc4a409d79fa62a735a7e1ff1a4232e6a7 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 4 Nov 2023 12:41:06 -0400 Subject: [PATCH] Add #[inline] to small functions in core --- library/core/src/alloc/layout.rs | 1 + library/core/src/alloc/mod.rs | 1 + library/core/src/any.rs | 1 + library/core/src/ascii.rs | 1 + library/core/src/ascii/ascii_char.rs | 1 + library/core/src/cell.rs | 2 ++ library/core/src/char/convert.rs | 1 + library/core/src/char/mod.rs | 12 ++++++++++++ library/core/src/escape.rs | 2 ++ library/core/src/ffi/c_str.rs | 2 ++ library/core/src/fmt/builders.rs | 8 ++++++++ library/core/src/fmt/float.rs | 4 ++++ library/core/src/fmt/mod.rs | 17 +++++++++++++++++ library/core/src/fmt/num.rs | 2 ++ library/core/src/iter/adapters/flatten.rs | 4 ++++ library/core/src/iter/traits/accum.rs | 1 + library/core/src/iter/traits/iterator.rs | 2 ++ library/core/src/mem/transmutability.rs | 2 ++ library/core/src/net/ip_addr.rs | 4 ++++ library/core/src/net/parser.rs | 19 +++++++++++++++++++ library/core/src/net/socket_addr.rs | 3 +++ library/core/src/num/bignum.rs | 3 +++ library/core/src/num/dec2flt/float.rs | 1 + library/core/src/num/error.rs | 1 + library/core/src/num/flt2dec/estimator.rs | 1 + library/core/src/num/int_macros.rs | 1 + library/core/src/num/mod.rs | 1 + library/core/src/num/uint_macros.rs | 1 + library/core/src/ops/range.rs | 1 + library/core/src/panicking.rs | 1 + library/core/src/slice/ascii.rs | 1 + library/core/src/slice/cmp.rs | 1 + library/core/src/str/count.rs | 1 + library/core/src/str/error.rs | 1 + library/core/src/str/mod.rs | 1 + library/core/src/unicode/unicode_data.rs | 8 ++++++++ 36 files changed, 114 insertions(+) diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 65946e09ff9ba..ab70a88530119 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -482,6 +482,7 @@ impl Error for LayoutError {} // (we need this for downstream impl of trait Error) #[stable(feature = "alloc_layout", since = "1.28.0")] impl fmt::Display for LayoutError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("invalid parameters to Layout::from_size_align") } diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 78091c0172955..fa38a50c8fba7 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -43,6 +43,7 @@ impl Error for AllocError {} // (we need this for downstream impl of trait Error) #[unstable(feature = "allocator_api", issue = "32838")] impl fmt::Display for AllocError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("memory allocation failed") } diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 8f5404d9713dd..f3e0d506f9530 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -630,6 +630,7 @@ impl TypeId { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_type_id", issue = "77125")] + #[inline] pub const fn of() -> TypeId { let t: u128 = intrinsics::type_id::(); TypeId { t } diff --git a/library/core/src/ascii.rs b/library/core/src/ascii.rs index ef8e4d098ed95..0a4d15c1bb532 100644 --- a/library/core/src/ascii.rs +++ b/library/core/src/ascii.rs @@ -90,6 +90,7 @@ pub struct EscapeDefault(escape::EscapeIterInner<4>); /// assert_eq!(b'd', escaped.next().unwrap()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[inline] pub fn escape_default(c: u8) -> EscapeDefault { let mut data = [Char::Null; 4]; let range = escape::escape_ascii_into(&mut data, c); diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index cc872a5343d6a..64cc974e6e473 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -559,6 +559,7 @@ impl [AsciiChar] { #[unstable(feature = "ascii_char", issue = "110998")] impl fmt::Display for AsciiChar { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ::fmt(self.as_str(), f) } diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 0978b3c92805e..55dbc66bc370b 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -722,6 +722,7 @@ impl Debug for BorrowError { #[stable(feature = "try_borrow", since = "1.13.0")] impl Display for BorrowError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Display::fmt("already mutably borrowed", f) } @@ -749,6 +750,7 @@ impl Debug for BorrowMutError { #[stable(feature = "try_borrow", since = "1.13.0")] impl Display for BorrowMutError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Display::fmt("already borrowed", f) } diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 453de9754be56..49675263623f8 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -264,6 +264,7 @@ pub struct CharTryFromError(()); #[stable(feature = "try_from", since = "1.34.0")] impl fmt::Display for CharTryFromError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "converted integer out of range for `char`".fmt(f) } diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index 5c42912874c66..e5fb2a0ab3861 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -152,6 +152,7 @@ pub const fn from_digit(num: u32, radix: u32) -> Option { pub struct EscapeUnicode(escape::EscapeIterInner<10>); impl EscapeUnicode { + #[inline] fn new(chr: char) -> Self { let mut data = [ascii::Char::Null; 10]; let range = escape::escape_unicode_into(&mut data, chr); @@ -219,11 +220,13 @@ impl fmt::Display for EscapeUnicode { pub struct EscapeDefault(escape::EscapeIterInner<10>); impl EscapeDefault { + #[inline] fn printable(chr: ascii::Char) -> Self { let data = [chr]; Self(escape::EscapeIterInner::from_array(data)) } + #[inline] fn backslash(chr: ascii::Char) -> Self { let data = [ascii::Char::ReverseSolidus, chr]; Self(escape::EscapeIterInner::from_array(data)) @@ -308,6 +311,7 @@ impl EscapeDebug { Self(EscapeDebugInner::Char(chr)) } + #[inline] fn backslash(chr: ascii::Char) -> Self { let data = [ascii::Char::ReverseSolidus, chr]; let iter = escape::EscapeIterInner::from_array(data); @@ -318,6 +322,7 @@ impl EscapeDebug { Self(EscapeDebugInner::Bytes(esc.0)) } + #[inline] fn clear(&mut self) { let bytes = escape::EscapeIterInner::from_array([]); self.0 = EscapeDebugInner::Bytes(bytes); @@ -386,6 +391,7 @@ pub struct ToLowercase(CaseMappingIter); #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for ToLowercase { type Item = char; + #[inline] fn next(&mut self) -> Option { self.0.next() } @@ -396,6 +402,7 @@ impl Iterator for ToLowercase { #[stable(feature = "case_mapping_double_ended", since = "1.59.0")] impl DoubleEndedIterator for ToLowercase { + #[inline] fn next_back(&mut self) -> Option { self.0.next_back() } @@ -420,6 +427,7 @@ pub struct ToUppercase(CaseMappingIter); #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for ToUppercase { type Item = char; + #[inline] fn next(&mut self) -> Option { self.0.next() } @@ -430,6 +438,7 @@ impl Iterator for ToUppercase { #[stable(feature = "case_mapping_double_ended", since = "1.59.0")] impl DoubleEndedIterator for ToUppercase { + #[inline] fn next_back(&mut self) -> Option { self.0.next_back() } @@ -534,6 +543,7 @@ impl fmt::Display for CaseMappingIter { #[stable(feature = "char_struct_display", since = "1.16.0")] impl fmt::Display for ToLowercase { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) } @@ -541,6 +551,7 @@ impl fmt::Display for ToLowercase { #[stable(feature = "char_struct_display", since = "1.16.0")] impl fmt::Display for ToUppercase { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) } @@ -553,6 +564,7 @@ pub struct TryFromCharError(pub(crate) ()); #[stable(feature = "u8_from_char", since = "1.59.0")] impl fmt::Display for TryFromCharError { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { "unicode code point out of range".fmt(fmt) } diff --git a/library/core/src/escape.rs b/library/core/src/escape.rs index 24bb9ad1ad1a2..365160ac23138 100644 --- a/library/core/src/escape.rs +++ b/library/core/src/escape.rs @@ -82,10 +82,12 @@ impl EscapeIterInner { Self::new(data, 0..M as u8) } + #[inline] pub fn as_ascii(&self) -> &[ascii::Char] { &self.data[usize::from(self.alive.start)..usize::from(self.alive.end)] } + #[inline] pub fn as_str(&self) -> &str { self.as_ascii().as_str() } diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index e7ec1fb73cdb5..8404d8af19b62 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -158,6 +158,7 @@ pub struct FromBytesUntilNulError(()); #[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")] impl fmt::Display for FromBytesUntilNulError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "data provided does not contain a nul") } @@ -623,6 +624,7 @@ impl CStr { /// ``` #[stable(feature = "cstr_to_str", since = "1.4.0")] #[rustc_const_stable(feature = "const_cstr_methods", since = "1.72.0")] + #[inline] pub const fn to_str(&self) -> Result<&str, str::Utf8Error> { // N.B., when `CStr` is changed to perform the length check in `.to_bytes()` // instead of in `from_ptr()`, it may be worth considering if this should diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 47db53ac6f34b..af5ea38818c61 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -18,6 +18,7 @@ impl Default for PadAdapterState { } impl<'buf, 'state> PadAdapter<'buf, 'state> { + #[inline] fn wrap<'slot, 'fmt: 'buf + 'slot>( fmt: &'fmt mut fmt::Formatter<'_>, slot: &'slot mut Option, @@ -91,6 +92,7 @@ pub struct DebugStruct<'a, 'b: 'a> { has_fields: bool, } +#[inline] pub(super) fn debug_struct_new<'a, 'b>( fmt: &'a mut fmt::Formatter<'b>, name: &str, @@ -281,6 +283,7 @@ pub struct DebugTuple<'a, 'b: 'a> { empty_name: bool, } +#[inline] pub(super) fn debug_tuple_new<'a, 'b>( fmt: &'a mut fmt::Formatter<'b>, name: &str, @@ -444,6 +447,7 @@ pub struct DebugSet<'a, 'b: 'a> { inner: DebugInner<'a, 'b>, } +#[inline] pub(super) fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b> { let result = fmt.write_str("{"); DebugSet { inner: DebugInner { fmt, result, has_fields: false } } @@ -474,6 +478,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> { /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut Self { self.inner.entry(entry); self @@ -574,6 +579,7 @@ pub struct DebugList<'a, 'b: 'a> { inner: DebugInner<'a, 'b>, } +#[inline] pub(super) fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a, 'b> { let result = fmt.write_str("["); DebugList { inner: DebugInner { fmt, result, has_fields: false } } @@ -604,6 +610,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> { /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut Self { self.inner.entry(entry); self @@ -709,6 +716,7 @@ pub struct DebugMap<'a, 'b: 'a> { state: PadAdapterState, } +#[inline] pub(super) fn debug_map_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugMap<'a, 'b> { let result = fmt.write_str("{"); DebugMap { fmt, result, has_fields: false, has_key: false, state: Default::default() } diff --git a/library/core/src/fmt/float.rs b/library/core/src/fmt/float.rs index 3bbf5d8770bd2..23fec294a94a0 100644 --- a/library/core/src/fmt/float.rs +++ b/library/core/src/fmt/float.rs @@ -198,6 +198,7 @@ macro_rules! floating { ($ty:ident) => { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for $ty { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { float_to_general_debug(fmt, self) } @@ -205,6 +206,7 @@ macro_rules! floating { #[stable(feature = "rust1", since = "1.0.0")] impl Display for $ty { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { float_to_decimal_display(fmt, self) } @@ -212,6 +214,7 @@ macro_rules! floating { #[stable(feature = "rust1", since = "1.0.0")] impl LowerExp for $ty { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { float_to_exponential_common(fmt, self, false) } @@ -219,6 +222,7 @@ macro_rules! floating { #[stable(feature = "rust1", since = "1.0.0")] impl UpperExp for $ty { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { float_to_exponential_common(fmt, self, true) } diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index c45ab094a20d6..c83d4ec98af20 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -188,6 +188,7 @@ pub trait Write { /// assert_eq!(&buf, "world"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] fn write_fmt(&mut self, args: Arguments<'_>) -> Result { // We use a specialization for `Sized` types to avoid an indirection // through `&mut self` @@ -431,6 +432,7 @@ impl<'a> Arguments<'a> { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for Arguments<'_> { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { Display::fmt(self, fmt) } @@ -438,6 +440,7 @@ impl Debug for Arguments<'_> { #[stable(feature = "rust1", since = "1.0.0")] impl Display for Arguments<'_> { + #[inline] fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { write(fmt.buf, *self) } @@ -1200,6 +1203,7 @@ impl PostPadding { } impl<'a> Formatter<'a> { + #[inline] fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c> where 'b: 'c, @@ -1489,6 +1493,7 @@ impl<'a> Formatter<'a> { /// /// Any `numfmt::Part::Copy` parts in `formatted` must contain valid UTF-8. unsafe fn write_formatted_parts(&mut self, formatted: &numfmt::Formatted<'_>) -> Result { + #[inline] unsafe fn write_bytes(buf: &mut dyn Write, s: &[u8]) -> Result { // SAFETY: This is used for `numfmt::Part::Num` and `numfmt::Part::Copy`. // It's safe to use for `numfmt::Part::Num` since every char `c` is between @@ -1556,6 +1561,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(format!("{Foo:0>8}"), "Foo"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn write_str(&mut self, data: &str) -> Result { self.buf.write_str(data) } @@ -1579,6 +1585,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result { write(self.buf, fmt) } @@ -1891,6 +1898,7 @@ impl<'a> Formatter<'a> { /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn debug_struct<'b>(&'b mut self, name: &str) -> DebugStruct<'b, 'a> { builders::debug_struct_new(self, name) } @@ -2045,6 +2053,7 @@ impl<'a> Formatter<'a> { /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn debug_tuple<'b>(&'b mut self, name: &str) -> DebugTuple<'b, 'a> { builders::debug_tuple_new(self, name) } @@ -2170,6 +2179,7 @@ impl<'a> Formatter<'a> { /// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "[10, 11]"); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> { builders::debug_list_new(self) } @@ -2228,6 +2238,7 @@ impl<'a> Formatter<'a> { /// } /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn debug_set<'b>(&'b mut self) -> DebugSet<'b, 'a> { builders::debug_set_new(self) } @@ -2254,6 +2265,7 @@ impl<'a> Formatter<'a> { /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] + #[inline] pub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a> { builders::debug_map_new(self) } @@ -2261,14 +2273,17 @@ impl<'a> Formatter<'a> { #[stable(since = "1.2.0", feature = "formatter_write")] impl Write for Formatter<'_> { + #[inline] fn write_str(&mut self, s: &str) -> Result { self.buf.write_str(s) } + #[inline] fn write_char(&mut self, c: char) -> Result { self.buf.write_char(c) } + #[inline] fn write_fmt(&mut self, args: Arguments<'_>) -> Result { write(self.buf, args) } @@ -2276,6 +2291,7 @@ impl Write for Formatter<'_> { #[stable(feature = "rust1", since = "1.0.0")] impl Display for Error { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { Display::fmt("an error occurred when formatting an argument", f) } @@ -2358,6 +2374,7 @@ impl Debug for str { #[stable(feature = "rust1", since = "1.0.0")] impl Display for str { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.pad(self) } diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 4f42f73ebbaff..6b164a1c69ac4 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -155,6 +155,7 @@ macro_rules! int_base { (fmt::$Trait:ident for $T:ident as $U:ident -> $Radix:ident) => { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::$Trait for $T { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { $Radix.fmt_int(*self as $U, f) } @@ -572,6 +573,7 @@ fn parse_u64_into(mut n: u64, buf: &mut [MaybeUninit; N], cu #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for u128 { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt_u128(*self, true, f) } diff --git a/library/core/src/iter/adapters/flatten.rs b/library/core/src/iter/adapters/flatten.rs index eee6e5bccecc7..81f1f642c27b0 100644 --- a/library/core/src/iter/adapters/flatten.rs +++ b/library/core/src/iter/adapters/flatten.rs @@ -15,6 +15,7 @@ pub struct FlatMap { } impl U> FlatMap { + #[inline] pub(in crate::iter) fn new(iter: I, f: F) -> FlatMap { FlatMap { inner: FlattenCompat::new(iter.map(f)) } } @@ -25,6 +26,7 @@ impl Clone for FlatMap where U: Clone + IntoIterator, { + #[inline] fn clone(&self) -> Self { FlatMap { inner: self.inner.clone() } } @@ -159,6 +161,7 @@ pub struct Flatten> { } impl> Flatten { + #[inline] pub(in super::super) fn new(iter: I) -> Flatten { Flatten { inner: FlattenCompat::new(iter) } } @@ -321,6 +324,7 @@ where I: Iterator, { /// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`. + #[inline] fn new(iter: I) -> FlattenCompat { FlattenCompat { iter: iter.fuse(), frontiter: None, backiter: None } } diff --git a/library/core/src/iter/traits/accum.rs b/library/core/src/iter/traits/accum.rs index f9c7eb8f9383e..426035a19e257 100644 --- a/library/core/src/iter/traits/accum.rs +++ b/library/core/src/iter/traits/accum.rs @@ -46,6 +46,7 @@ macro_rules! integer_sum_product { (@impls $zero:expr, $one:expr, #[$attr:meta], $($a:ty)*) => ($( #[$attr] impl Sum for $a { + #[inline] fn sum>(iter: I) -> Self { iter.fold( $zero, diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 6adea444214eb..902776ff46721 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -3627,6 +3627,7 @@ pub trait Iterator { /// ``` #[stable(feature = "iter_arith", since = "1.11.0")] #[rustc_do_not_const_check] + #[inline] fn sum(self) -> S where Self: Sized, @@ -3682,6 +3683,7 @@ pub trait Iterator { /// ``` #[stable(feature = "iter_order", since = "1.5.0")] #[rustc_do_not_const_check] + #[inline] fn cmp(self, other: I) -> Ordering where I: IntoIterator, diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index f5cc86e7767e8..6e57abf90098a 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -91,6 +91,7 @@ impl Assume { impl core::ops::Add for Assume { type Output = Assume; + #[inline] fn add(self, other_assumptions: Assume) -> Assume { self.and(other_assumptions) } @@ -102,6 +103,7 @@ impl core::ops::Add for Assume { impl core::ops::Sub for Assume { type Output = Assume; + #[inline] fn sub(self, other_assumptions: Assume) -> Assume { self.but_not(other_assumptions) } diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index b7eca9b168a12..9223bbf370df3 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -986,6 +986,7 @@ impl fmt::Display for IpAddr { #[stable(feature = "ip_addr", since = "1.7.0")] impl fmt::Debug for IpAddr { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } @@ -1058,6 +1059,7 @@ impl fmt::Display for Ipv4Addr { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Ipv4Addr { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } @@ -1929,6 +1931,7 @@ impl fmt::Display for Ipv6Addr { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for Ipv6Addr { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } @@ -2191,6 +2194,7 @@ macro_rules! bitop_impls { $(#[$attr])* impl $BitOpAssign<&'_ $ty> for $ty { + #[inline] fn $bitop_assign(&mut self, rhs: &'_ $ty) { self.$bitop_assign(*rhs); } diff --git a/library/core/src/net/parser.rs b/library/core/src/net/parser.rs index b9a1924d66898..f655e156a1dfc 100644 --- a/library/core/src/net/parser.rs +++ b/library/core/src/net/parser.rs @@ -79,6 +79,7 @@ impl<'a> Parser<'a> { #[must_use] /// Read the next character from the input if it matches the target. + #[inline] fn read_given_char(&mut self, target: char) -> Option<()> { self.read_atomically(|p| { p.read_char().and_then(|c| if c == target { Some(()) } else { None }) @@ -89,6 +90,7 @@ impl<'a> Parser<'a> { /// character iff index > 0, then runs the parser. When used in a loop, /// the separator character will only be read on index > 0 (see /// read_ipv4_addr for an example) + #[inline] fn read_separator(&mut self, sep: char, index: usize, inner: F) -> Option where F: FnOnce(&mut Parser<'_>) -> Option, @@ -137,6 +139,7 @@ impl<'a> Parser<'a> { } /// Read an IPv4 address. + #[inline] fn read_ipv4_addr(&mut self) -> Option { self.read_atomically(|p| { let mut groups = [0; 4]; @@ -154,6 +157,7 @@ impl<'a> Parser<'a> { } /// Read an IPv6 Address. + #[inline] fn read_ipv6_addr(&mut self) -> Option { /// Read a chunk of an IPv6 address into `groups`. Returns the number /// of groups read, along with a bool indicating if an embedded @@ -226,6 +230,7 @@ impl<'a> Parser<'a> { } /// Read a `:` followed by a port in base 10. + #[inline] fn read_port(&mut self) -> Option { self.read_atomically(|p| { p.read_given_char(':')?; @@ -234,6 +239,7 @@ impl<'a> Parser<'a> { } /// Read a `%` followed by a scope ID in base 10. + #[inline] fn read_scope_id(&mut self) -> Option { self.read_atomically(|p| { p.read_given_char('%')?; @@ -242,6 +248,7 @@ impl<'a> Parser<'a> { } /// Read an IPv4 address with a port. + #[inline] fn read_socket_addr_v4(&mut self) -> Option { self.read_atomically(|p| { let ip = p.read_ipv4_addr()?; @@ -251,6 +258,7 @@ impl<'a> Parser<'a> { } /// Read an IPv6 address with a port. + #[inline] fn read_socket_addr_v6(&mut self) -> Option { self.read_atomically(|p| { p.read_given_char('[')?; @@ -286,6 +294,7 @@ impl IpAddr { /// assert_eq!(IpAddr::parse_ascii(b"::1"), Ok(localhost_v6)); /// ``` #[unstable(feature = "addr_parse_ascii", issue = "101035")] + #[inline] pub fn parse_ascii(b: &[u8]) -> Result { Parser::new(b).parse_with(|p| p.read_ip_addr(), AddrKind::Ip) } @@ -294,6 +303,7 @@ impl IpAddr { #[stable(feature = "ip_addr", since = "1.7.0")] impl FromStr for IpAddr { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } @@ -325,6 +335,7 @@ impl Ipv4Addr { #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for Ipv4Addr { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } @@ -343,6 +354,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::parse_ascii(b"::1"), Ok(localhost)); /// ``` #[unstable(feature = "addr_parse_ascii", issue = "101035")] + #[inline] pub fn parse_ascii(b: &[u8]) -> Result { Parser::new(b).parse_with(|p| p.read_ipv6_addr(), AddrKind::Ipv6) } @@ -351,6 +363,7 @@ impl Ipv6Addr { #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for Ipv6Addr { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } @@ -369,6 +382,7 @@ impl SocketAddrV4 { /// assert_eq!(SocketAddrV4::parse_ascii(b"127.0.0.1:8080"), Ok(socket)); /// ``` #[unstable(feature = "addr_parse_ascii", issue = "101035")] + #[inline] pub fn parse_ascii(b: &[u8]) -> Result { Parser::new(b).parse_with(|p| p.read_socket_addr_v4(), AddrKind::SocketV4) } @@ -377,6 +391,7 @@ impl SocketAddrV4 { #[stable(feature = "socket_addr_from_str", since = "1.5.0")] impl FromStr for SocketAddrV4 { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } @@ -395,6 +410,7 @@ impl SocketAddrV6 { /// assert_eq!(SocketAddrV6::parse_ascii(b"[2001:db8::1]:8080"), Ok(socket)); /// ``` #[unstable(feature = "addr_parse_ascii", issue = "101035")] + #[inline] pub fn parse_ascii(b: &[u8]) -> Result { Parser::new(b).parse_with(|p| p.read_socket_addr_v6(), AddrKind::SocketV6) } @@ -403,6 +419,7 @@ impl SocketAddrV6 { #[stable(feature = "socket_addr_from_str", since = "1.5.0")] impl FromStr for SocketAddrV6 { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } @@ -423,6 +440,7 @@ impl SocketAddr { /// assert_eq!(SocketAddr::parse_ascii(b"[::1]:8080"), Ok(socket_v6)); /// ``` #[unstable(feature = "addr_parse_ascii", issue = "101035")] + #[inline] pub fn parse_ascii(b: &[u8]) -> Result { Parser::new(b).parse_with(|p| p.read_socket_addr(), AddrKind::Socket) } @@ -431,6 +449,7 @@ impl SocketAddr { #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for SocketAddr { type Err = AddrParseError; + #[inline] fn from_str(s: &str) -> Result { Self::parse_ascii(s.as_bytes()) } diff --git a/library/core/src/net/socket_addr.rs b/library/core/src/net/socket_addr.rs index 55116285842aa..09508dfefd55a 100644 --- a/library/core/src/net/socket_addr.rs +++ b/library/core/src/net/socket_addr.rs @@ -578,6 +578,7 @@ impl fmt::Display for SocketAddr { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for SocketAddr { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } @@ -604,6 +605,7 @@ impl fmt::Display for SocketAddrV4 { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for SocketAddrV4 { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } @@ -638,6 +640,7 @@ impl fmt::Display for SocketAddrV6 { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for SocketAddrV6 { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } diff --git a/library/core/src/num/bignum.rs b/library/core/src/num/bignum.rs index d2a21b6b38260..7e7fef3723eac 100644 --- a/library/core/src/num/bignum.rs +++ b/library/core/src/num/bignum.rs @@ -111,6 +111,7 @@ macro_rules! define_bignum { /// Returns the internal digits as a slice `[a, b, c, ...]` such that the numeric /// value is `a + b * 2^W + c * 2^(2W) + ...` where `W` is the number of bits in /// the digit type. + #[inline] pub fn digits(&self) -> &[$ty] { &self.base[..self.size] } @@ -378,6 +379,7 @@ macro_rules! define_bignum { } impl crate::cmp::PartialEq for $name { + #[inline] fn eq(&self, other: &$name) -> bool { self.base[..] == other.base[..] } @@ -386,6 +388,7 @@ macro_rules! define_bignum { impl crate::cmp::Eq for $name {} impl crate::cmp::PartialOrd for $name { + #[inline] fn partial_cmp(&self, other: &$name) -> crate::option::Option { crate::option::Option::Some(self.cmp(other)) } diff --git a/library/core/src/num/dec2flt/float.rs b/library/core/src/num/dec2flt/float.rs index 1c9d68999d6f8..05f932958394a 100644 --- a/library/core/src/num/dec2flt/float.rs +++ b/library/core/src/num/dec2flt/float.rs @@ -148,6 +148,7 @@ impl RawFloat for f32 { (mantissa as u64, exponent, sign) } + #[inline] fn classify(self) -> FpCategory { self.classify() } diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 14e99578a7c7d..fd8871fdccfae 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -11,6 +11,7 @@ pub struct TryFromIntError(pub(crate) ()); #[stable(feature = "try_from", since = "1.34.0")] impl fmt::Display for TryFromIntError { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { #[allow(deprecated)] self.description().fmt(fmt) diff --git a/library/core/src/num/flt2dec/estimator.rs b/library/core/src/num/flt2dec/estimator.rs index 50e2f70528383..e28aac8827f14 100644 --- a/library/core/src/num/flt2dec/estimator.rs +++ b/library/core/src/num/flt2dec/estimator.rs @@ -5,6 +5,7 @@ /// This is used to approximate `k = ceil(log_10 (mant * 2^exp))`; /// the true `k` is either `k_0` or `k_0+1`. #[doc(hidden)] +#[inline] pub fn estimate_scaling_factor(mant: u64, exp: i16) -> i16 { // 2^(nbits-1) < mant <= 2^nbits if mant > 0 let nbits = 64 - (mant - 1).leading_zeros() as i64; diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index fd01f1b261012..454bdb6baeb8c 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -82,6 +82,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::from_str_radix(\"A\", 16), Ok(10));")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn from_str_radix(src: &str, radix: u32) -> Result { from_str_radix(src, radix) } diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 2a0b31404f035..2f41dc787fb21 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1390,6 +1390,7 @@ macro_rules! from_str_radix_int_impl { #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for $t { type Err = ParseIntError; + #[inline] fn from_str(src: &str) -> Result { from_str_radix(src, 10) } diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 11a53aaf122ec..c341d63fff1a8 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -81,6 +81,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::from_str_radix(\"A\", 16), Ok(10));")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn from_str_radix(src: &str, radix: u32) -> Result { from_str_radix(src, radix) } diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index b419a738fbe3a..e90eade001aeb 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -44,6 +44,7 @@ pub struct RangeFull; #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for RangeFull { + #[inline] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "..") } diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 39a5e8d9fe2ec..8b1991170ad29 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -292,6 +292,7 @@ pub fn assert_matches_failed( // The pattern is a string so it can be displayed directly. struct Pattern<'a>(&'a str); impl fmt::Debug for Pattern<'_> { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.0) } diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 4cfccd2e3ce0f..d9f2ff160dbc1 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -241,6 +241,7 @@ impl<'a> iter::Iterator for EscapeAscii<'a> { #[stable(feature = "inherent_ascii_escape", since = "1.60.0")] impl<'a> iter::DoubleEndedIterator for EscapeAscii<'a> { + #[inline] fn next_back(&mut self) -> Option { self.inner.next_back() } diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index 075347b80d031..3892d51e800ae 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -12,6 +12,7 @@ impl PartialEq<[B]> for [A] where A: PartialEq, { + #[inline] fn eq(&self, other: &[B]) -> bool { SlicePartialEq::equal(self, other) } diff --git a/library/core/src/str/count.rs b/library/core/src/str/count.rs index 28567a7e753aa..02e8e660780c6 100644 --- a/library/core/src/str/count.rs +++ b/library/core/src/str/count.rs @@ -131,6 +131,7 @@ fn sum_bytes_in_usize(values: usize) -> usize { // bytes in the string which are not continuation bytes", and is used for the // head and tail of the input string (the first and last item in the tuple // returned by `slice::align_to`). +#[inline] fn char_count_general_case(s: &[u8]) -> usize { s.iter().filter(|&&byte| !super::validations::utf8_is_cont_byte(byte)).count() } diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index a11b5add42ebf..ecb27ab92e078 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -141,6 +141,7 @@ pub struct ParseBoolError; #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for ParseBoolError { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "provided string was not `true` or `false`".fmt(f) } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 27178328be5c1..727004511f3a7 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1100,6 +1100,7 @@ impl str { /// assert!(!bananas.ends_with("nana")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn ends_with<'a, P>(&'a self, pat: P) -> bool where P: Pattern<'a, Searcher: ReverseSearcher<'a>>, diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index b25e9df286808..52fc6b8f87152 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -169,6 +169,7 @@ pub mod alphabetic { 4, 1, 7, 1, 4, 1, 4, 1, 1, 1, 10, 1, 17, 5, 3, 1, 5, 1, 17, 0, 26, 6, 26, 6, 26, 0, 0, 32, 0, 6, 222, 2, 0, 14, 0, 0, 0, 0, 0, 5, 0, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -221,6 +222,7 @@ pub mod case_ignorable { 0, 55, 4, 50, 8, 1, 14, 1, 22, 5, 1, 15, 0, 7, 1, 17, 2, 7, 1, 2, 1, 5, 5, 62, 33, 1, 160, 14, 0, 1, 61, 4, 0, 5, 0, 7, 109, 8, 0, 5, 0, 1, 30, 96, 128, 240, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -251,6 +253,7 @@ pub mod cased { 25, 1, 25, 1, 31, 1, 25, 1, 31, 1, 25, 1, 31, 1, 25, 1, 31, 1, 25, 1, 8, 0, 10, 1, 20, 6, 6, 0, 62, 0, 68, 0, 26, 6, 26, 6, 26, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -268,6 +271,7 @@ pub mod cc { static OFFSETS: [u8; 5] = [ 0, 32, 95, 33, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -315,6 +319,7 @@ pub mod grapheme_extend { 15, 0, 7, 1, 17, 2, 7, 1, 2, 1, 5, 100, 1, 160, 7, 0, 1, 61, 4, 0, 4, 0, 7, 109, 7, 0, 96, 128, 240, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -419,6 +424,7 @@ pub mod lowercase { ]; #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] + #[inline] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32, @@ -453,6 +459,7 @@ pub mod n { 23, 0, 20, 12, 20, 108, 25, 0, 50, 0, 10, 0, 10, 0, 10, 0, 9, 128, 10, 0, 59, 1, 3, 1, 4, 76, 45, 1, 15, 0, 13, 0, 10, 0, ]; + #[inline] pub fn lookup(c: char) -> bool { super::skip_search( c as u32, @@ -542,6 +549,7 @@ pub mod uppercase { ]; #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] + #[inline] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32,