Skip to content

Commit ab949b8

Browse files
committed
Add #[inline] to small functions in core
1 parent cdca82c commit ab949b8

40 files changed

+246
-124
lines changed

library/core/src/array/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ impl fmt::Display for TryFromSliceError {
143143
#[stable(feature = "try_from", since = "1.34.0")]
144144
impl Error for TryFromSliceError {
145145
#[allow(deprecated)]
146+
#[inline]
146147
fn description(&self) -> &str {
147148
"could not convert slice to array"
148149
}
149150
}
150151

151152
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
152153
impl From<Infallible> for TryFromSliceError {
154+
#[inline]
153155
fn from(x: Infallible) -> TryFromSliceError {
154156
match x {}
155157
}

library/core/src/char/convert.rs

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ enum CharErrorKind {
190190
#[stable(feature = "char_from_str", since = "1.20.0")]
191191
impl Error for ParseCharError {
192192
#[allow(deprecated)]
193+
#[inline]
193194
fn description(&self) -> &str {
194195
match self.kind {
195196
CharErrorKind::EmptyString => "cannot parse char from empty string",

library/core/src/char/decode.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl DecodeUtf16Error {
109109
/// Returns the unpaired surrogate which caused this error.
110110
#[must_use]
111111
#[stable(feature = "decode_utf16", since = "1.9.0")]
112+
#[inline]
112113
pub fn unpaired_surrogate(&self) -> u16 {
113114
self.code
114115
}
@@ -124,6 +125,7 @@ impl fmt::Display for DecodeUtf16Error {
124125
#[stable(feature = "decode_utf16", since = "1.9.0")]
125126
impl Error for DecodeUtf16Error {
126127
#[allow(deprecated)]
128+
#[inline]
127129
fn description(&self) -> &str {
128130
"unpaired surrogate found"
129131
}

library/core/src/char/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl EscapeDefault {
229229
Self(escape::EscapeIterInner::from_array(data))
230230
}
231231

232+
#[inline]
232233
fn from_unicode(esc: EscapeUnicode) -> Self {
233234
Self(esc.0)
234235
}
@@ -304,6 +305,7 @@ enum EscapeDebugInner {
304305
}
305306

306307
impl EscapeDebug {
308+
#[inline]
307309
fn printable(chr: char) -> Self {
308310
Self(EscapeDebugInner::Char(chr))
309311
}
@@ -314,6 +316,7 @@ impl EscapeDebug {
314316
Self(EscapeDebugInner::Bytes(iter))
315317
}
316318

319+
#[inline]
317320
fn from_unicode(esc: EscapeUnicode) -> Self {
318321
Self(EscapeDebugInner::Bytes(esc.0))
319322
}
@@ -339,6 +342,7 @@ impl Iterator for EscapeDebug {
339342
}
340343
}
341344

345+
#[inline]
342346
fn size_hint(&self) -> (usize, Option<usize>) {
343347
let n = self.len();
344348
(n, Some(n))
@@ -352,6 +356,7 @@ impl Iterator for EscapeDebug {
352356

353357
#[stable(feature = "char_escape_debug", since = "1.20.0")]
354358
impl ExactSizeIterator for EscapeDebug {
359+
#[inline]
355360
fn len(&self) -> usize {
356361
match &self.0 {
357362
EscapeDebugInner::Bytes(bytes) => bytes.len(),
@@ -389,6 +394,7 @@ impl Iterator for ToLowercase {
389394
fn next(&mut self) -> Option<char> {
390395
self.0.next()
391396
}
397+
#[inline]
392398
fn size_hint(&self) -> (usize, Option<usize>) {
393399
self.0.size_hint()
394400
}
@@ -423,6 +429,7 @@ impl Iterator for ToUppercase {
423429
fn next(&mut self) -> Option<char> {
424430
self.0.next()
425431
}
432+
#[inline]
426433
fn size_hint(&self) -> (usize, Option<usize>) {
427434
self.0.size_hint()
428435
}
@@ -450,6 +457,7 @@ enum CaseMappingIter {
450457
}
451458

452459
impl CaseMappingIter {
460+
#[inline]
453461
fn new(chars: [char; 3]) -> CaseMappingIter {
454462
if chars[2] == '\0' {
455463
if chars[1] == '\0' {
@@ -465,6 +473,7 @@ impl CaseMappingIter {
465473

466474
impl Iterator for CaseMappingIter {
467475
type Item = char;
476+
#[inline]
468477
fn next(&mut self) -> Option<char> {
469478
match *self {
470479
CaseMappingIter::Three(a, b, c) => {
@@ -483,6 +492,7 @@ impl Iterator for CaseMappingIter {
483492
}
484493
}
485494

495+
#[inline]
486496
fn size_hint(&self) -> (usize, Option<usize>) {
487497
let size = match self {
488498
CaseMappingIter::Three(..) => 3,
@@ -495,6 +505,7 @@ impl Iterator for CaseMappingIter {
495505
}
496506

497507
impl DoubleEndedIterator for CaseMappingIter {
508+
#[inline]
498509
fn next_back(&mut self) -> Option<char> {
499510
match *self {
500511
CaseMappingIter::Three(a, b, c) => {

library/core/src/convert/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -862,34 +862,39 @@ pub enum Infallible {}
862862

863863
#[stable(feature = "convert_infallible", since = "1.34.0")]
864864
impl Clone for Infallible {
865+
#[inline]
865866
fn clone(&self) -> Infallible {
866867
match *self {}
867868
}
868869
}
869870

870871
#[stable(feature = "convert_infallible", since = "1.34.0")]
871872
impl fmt::Debug for Infallible {
873+
#[inline]
872874
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
873875
match *self {}
874876
}
875877
}
876878

877879
#[stable(feature = "convert_infallible", since = "1.34.0")]
878880
impl fmt::Display for Infallible {
881+
#[inline]
879882
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
880883
match *self {}
881884
}
882885
}
883886

884887
#[stable(feature = "str_parse_error2", since = "1.8.0")]
885888
impl Error for Infallible {
889+
#[inline]
886890
fn description(&self) -> &str {
887891
match *self {}
888892
}
889893
}
890894

891895
#[stable(feature = "convert_infallible", since = "1.34.0")]
892896
impl PartialEq for Infallible {
897+
#[inline]
893898
fn eq(&self, _: &Infallible) -> bool {
894899
match *self {}
895900
}
@@ -900,13 +905,15 @@ impl Eq for Infallible {}
900905

901906
#[stable(feature = "convert_infallible", since = "1.34.0")]
902907
impl PartialOrd for Infallible {
908+
#[inline]
903909
fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
904910
match *self {}
905911
}
906912
}
907913

908914
#[stable(feature = "convert_infallible", since = "1.34.0")]
909915
impl Ord for Infallible {
916+
#[inline]
910917
fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
911918
match *self {}
912919
}

library/core/src/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub struct Request<'a>(dyn Erased<'a> + 'a);
514514

515515
impl<'a> Request<'a> {
516516
/// Create a new `&mut Request` from a `&mut dyn Erased` trait object.
517+
#[inline]
517518
fn new<'b>(erased: &'b mut (dyn Erased<'a> + 'a)) -> &'b mut Request<'a> {
518519
// SAFETY: transmuting `&mut (dyn Erased<'a> + 'a)` to `&mut Request<'a>` is safe since
519520
// `Request` is repr(transparent).
@@ -1046,6 +1047,7 @@ impl<'a, T: Error + ?Sized> Error for &'a T {
10461047
#[stable(feature = "fmt_error", since = "1.11.0")]
10471048
impl Error for crate::fmt::Error {
10481049
#[allow(deprecated)]
1050+
#[inline]
10491051
fn description(&self) -> &str {
10501052
"an error occurred when formatting an argument"
10511053
}
@@ -1054,6 +1056,7 @@ impl Error for crate::fmt::Error {
10541056
#[stable(feature = "try_borrow", since = "1.13.0")]
10551057
impl Error for crate::cell::BorrowError {
10561058
#[allow(deprecated)]
1059+
#[inline]
10571060
fn description(&self) -> &str {
10581061
"already mutably borrowed"
10591062
}
@@ -1062,6 +1065,7 @@ impl Error for crate::cell::BorrowError {
10621065
#[stable(feature = "try_borrow", since = "1.13.0")]
10631066
impl Error for crate::cell::BorrowMutError {
10641067
#[allow(deprecated)]
1068+
#[inline]
10651069
fn description(&self) -> &str {
10661070
"already borrowed"
10671071
}
@@ -1070,6 +1074,7 @@ impl Error for crate::cell::BorrowMutError {
10701074
#[stable(feature = "try_from", since = "1.34.0")]
10711075
impl Error for crate::char::CharTryFromError {
10721076
#[allow(deprecated)]
1077+
#[inline]
10731078
fn description(&self) -> &str {
10741079
"converted integer out of range for `char`"
10751080
}

library/core/src/ffi/c_str.rs

+4
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ enum FromBytesWithNulErrorKind {
124124
}
125125

126126
impl FromBytesWithNulError {
127+
#[inline]
127128
const fn interior_nul(pos: usize) -> FromBytesWithNulError {
128129
FromBytesWithNulError { kind: FromBytesWithNulErrorKind::InteriorNul(pos) }
129130
}
131+
#[inline]
130132
const fn not_nul_terminated() -> FromBytesWithNulError {
131133
FromBytesWithNulError { kind: FromBytesWithNulErrorKind::NotNulTerminated }
132134
}
@@ -135,6 +137,7 @@ impl FromBytesWithNulError {
135137
#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
136138
impl Error for FromBytesWithNulError {
137139
#[allow(deprecated)]
140+
#[inline]
138141
fn description(&self) -> &str {
139142
match self.kind {
140143
FromBytesWithNulErrorKind::InteriorNul(..) => {
@@ -695,6 +698,7 @@ impl AsRef<CStr> for CStr {
695698
/// located within `isize::MAX` from `ptr`.
696699
#[inline]
697700
const unsafe fn const_strlen(ptr: *const c_char) -> usize {
701+
#[inline]
698702
const fn strlen_ct(s: *const c_char) -> usize {
699703
let mut len = 0;
700704

library/core/src/ffi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ impl<'f> Clone for VaListImpl<'f> {
612612
issue = "44930"
613613
)]
614614
impl<'f> Drop for VaListImpl<'f> {
615+
#[inline]
615616
fn drop(&mut self) {
616617
// FIXME: this should call `va_end`, but there's no clean way to
617618
// guarantee that `drop` always gets inlined into its caller,

library/core/src/fmt/builders.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct PadAdapterState {
1212
}
1313

1414
impl Default for PadAdapterState {
15+
#[inline]
1516
fn default() -> Self {
1617
PadAdapterState { on_newline: true }
1718
}

library/core/src/fmt/float.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trait GeneralFormat: PartialOrd {
1313
macro_rules! impl_general_format {
1414
($($t:ident)*) => {
1515
$(impl GeneralFormat for $t {
16+
#[inline]
1617
fn already_rounded_value_should_use_exponential(&self) -> bool {
1718
let abs = $t::abs_private(*self);
1819
(abs != 0.0 && abs < 1e-4) || abs >= 1e+16

library/core/src/fmt/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ impl<'a> Formatter<'a> {
259259
/// Currently not intended for use outside of the standard library.
260260
#[unstable(feature = "fmt_internals", reason = "internal to standard library", issue = "none")]
261261
#[doc(hidden)]
262+
#[inline]
262263
pub fn new(buf: &'a mut (dyn Write + 'a)) -> Formatter<'a> {
263264
Formatter {
264265
flags: 0,
@@ -1590,6 +1591,7 @@ impl<'a> Formatter<'a> {
15901591
note = "use the `sign_plus`, `sign_minus`, `alternate`, \
15911592
or `sign_aware_zero_pad` methods instead"
15921593
)]
1594+
#[inline]
15931595
pub fn flags(&self) -> u32 {
15941596
self.flags
15951597
}
@@ -1623,6 +1625,7 @@ impl<'a> Formatter<'a> {
16231625
/// ```
16241626
#[must_use]
16251627
#[stable(feature = "fmt_flags", since = "1.5.0")]
1628+
#[inline]
16261629
pub fn fill(&self) -> char {
16271630
self.fill
16281631
}
@@ -1658,6 +1661,7 @@ impl<'a> Formatter<'a> {
16581661
/// ```
16591662
#[must_use]
16601663
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
1664+
#[inline]
16611665
pub fn align(&self) -> Option<Alignment> {
16621666
match self.align {
16631667
rt::Alignment::Left => Some(Alignment::Left),
@@ -1693,6 +1697,7 @@ impl<'a> Formatter<'a> {
16931697
/// ```
16941698
#[must_use]
16951699
#[stable(feature = "fmt_flags", since = "1.5.0")]
1700+
#[inline]
16961701
pub fn width(&self) -> Option<usize> {
16971702
self.width
16981703
}
@@ -1724,6 +1729,7 @@ impl<'a> Formatter<'a> {
17241729
/// ```
17251730
#[must_use]
17261731
#[stable(feature = "fmt_flags", since = "1.5.0")]
1732+
#[inline]
17271733
pub fn precision(&self) -> Option<usize> {
17281734
self.precision
17291735
}
@@ -1756,6 +1762,7 @@ impl<'a> Formatter<'a> {
17561762
/// ```
17571763
#[must_use]
17581764
#[stable(feature = "fmt_flags", since = "1.5.0")]
1765+
#[inline]
17591766
pub fn sign_plus(&self) -> bool {
17601767
self.flags & (1 << rt::Flag::SignPlus as u32) != 0
17611768
}
@@ -1785,6 +1792,7 @@ impl<'a> Formatter<'a> {
17851792
/// ```
17861793
#[must_use]
17871794
#[stable(feature = "fmt_flags", since = "1.5.0")]
1795+
#[inline]
17881796
pub fn sign_minus(&self) -> bool {
17891797
self.flags & (1 << rt::Flag::SignMinus as u32) != 0
17901798
}
@@ -1813,6 +1821,7 @@ impl<'a> Formatter<'a> {
18131821
/// ```
18141822
#[must_use]
18151823
#[stable(feature = "fmt_flags", since = "1.5.0")]
1824+
#[inline]
18161825
pub fn alternate(&self) -> bool {
18171826
self.flags & (1 << rt::Flag::Alternate as u32) != 0
18181827
}
@@ -1839,16 +1848,19 @@ impl<'a> Formatter<'a> {
18391848
/// ```
18401849
#[must_use]
18411850
#[stable(feature = "fmt_flags", since = "1.5.0")]
1851+
#[inline]
18421852
pub fn sign_aware_zero_pad(&self) -> bool {
18431853
self.flags & (1 << rt::Flag::SignAwareZeroPad as u32) != 0
18441854
}
18451855

18461856
// FIXME: Decide what public API we want for these two flags.
18471857
// https://github.com/rust-lang/rust/issues/48584
1858+
#[inline]
18481859
fn debug_lower_hex(&self) -> bool {
18491860
self.flags & (1 << rt::Flag::DebugLowerHex as u32) != 0
18501861
}
18511862

1863+
#[inline]
18521864
fn debug_upper_hex(&self) -> bool {
18531865
self.flags & (1 << rt::Flag::DebugUpperHex as u32) != 0
18541866
}

0 commit comments

Comments
 (0)