Skip to content

Commit f8d485f

Browse files
committedJul 22, 2017
Auto merge of rust-lang#43367 - alexcrichton:remove-inline-always, r=sfackler
std: Cut down #[inline] annotations where not necessary This PR cuts down on a large number of `#[inline(always)]` and `#[inline]` annotations in libcore for various core functions. The `#[inline(always)]` annotation is almost never needed and is detrimental to debug build times as it forces LLVM to perform inlining when it otherwise wouldn't need to in debug builds. Additionally `#[inline]` is an unnecessary annoation on almost all generic functions because the function will already be monomorphized into other codegen units and otherwise rarely needs the extra "help" from us to tell LLVM to inline something. Overall this PR cut the compile time of a [microbenchmark][1] by 30% from 1s to 0.7s. [1]: https://gist.github.com/alexcrichton/a7d70319a45aa60cf36a6a7bf540dd3a
2 parents 35f6499 + 53d8b1d commit f8d485f

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed
 

‎src/libcore/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait Clone : Sized {
106106
/// `a.clone_from(&b)` is equivalent to `a = b.clone()` in functionality,
107107
/// but can be overridden to reuse the resources of `a` to avoid unnecessary
108108
/// allocations.
109-
#[inline(always)]
109+
#[inline]
110110
#[stable(feature = "rust1", since = "1.0.0")]
111111
fn clone_from(&mut self, source: &Self) {
112112
*self = source.clone()

‎src/libcore/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub trait Eq: PartialEq<Self> {
168168
//
169169
// This should never be implemented by hand.
170170
#[doc(hidden)]
171-
#[inline(always)]
171+
#[inline]
172172
#[stable(feature = "rust1", since = "1.0.0")]
173173
fn assert_receiver_is_total_eq(&self) {}
174174
}

‎src/libcore/hash/sip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<S: Sip> Hasher<S> {
239239
// except for composite types (that includes slices and str hashing because of delimiter).
240240
// Without this extra push the compiler is very reluctant to inline delimiter writes,
241241
// degrading performance substantially for the most common use cases.
242-
#[inline(always)]
242+
#[inline]
243243
fn short_write(&mut self, msg: &[u8]) {
244244
debug_assert!(msg.len() <= 8);
245245
let length = msg.len();

‎src/libcore/nonzero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct NonZero<T: Zeroable>(T);
4242
impl<T: Zeroable> NonZero<T> {
4343
/// Creates an instance of NonZero with the provided value.
4444
/// You must indeed ensure that the value is actually "non-zero".
45-
#[inline(always)]
45+
#[inline]
4646
pub const unsafe fn new(inner: T) -> NonZero<T> {
4747
NonZero(inner)
4848
}

‎src/libcore/num/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ macro_rules! int_impl {
695695
/// assert_eq!((-128i8).wrapping_div(-1), -128);
696696
/// ```
697697
#[stable(feature = "num_wrapping", since = "1.2.0")]
698-
#[inline(always)]
698+
#[inline]
699699
pub fn wrapping_div(self, rhs: Self) -> Self {
700700
self.overflowing_div(rhs).0
701701
}
@@ -721,7 +721,7 @@ macro_rules! int_impl {
721721
/// assert_eq!((-128i8).wrapping_rem(-1), 0);
722722
/// ```
723723
#[stable(feature = "num_wrapping", since = "1.2.0")]
724-
#[inline(always)]
724+
#[inline]
725725
pub fn wrapping_rem(self, rhs: Self) -> Self {
726726
self.overflowing_rem(rhs).0
727727
}
@@ -744,7 +744,7 @@ macro_rules! int_impl {
744744
/// assert_eq!((-128i8).wrapping_neg(), -128);
745745
/// ```
746746
#[stable(feature = "num_wrapping", since = "1.2.0")]
747-
#[inline(always)]
747+
#[inline]
748748
pub fn wrapping_neg(self) -> Self {
749749
self.overflowing_neg().0
750750
}
@@ -769,7 +769,7 @@ macro_rules! int_impl {
769769
/// assert_eq!((-1i8).wrapping_shl(8), -1);
770770
/// ```
771771
#[stable(feature = "num_wrapping", since = "1.2.0")]
772-
#[inline(always)]
772+
#[inline]
773773
pub fn wrapping_shl(self, rhs: u32) -> Self {
774774
unsafe {
775775
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
@@ -796,7 +796,7 @@ macro_rules! int_impl {
796796
/// assert_eq!((-128i8).wrapping_shr(8), -128);
797797
/// ```
798798
#[stable(feature = "num_wrapping", since = "1.2.0")]
799-
#[inline(always)]
799+
#[inline]
800800
pub fn wrapping_shr(self, rhs: u32) -> Self {
801801
unsafe {
802802
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
@@ -822,7 +822,7 @@ macro_rules! int_impl {
822822
/// assert_eq!((-128i8).wrapping_abs() as u8, 128);
823823
/// ```
824824
#[stable(feature = "no_panic_abs", since = "1.13.0")]
825-
#[inline(always)]
825+
#[inline]
826826
pub fn wrapping_abs(self) -> Self {
827827
if self.is_negative() {
828828
self.wrapping_neg()
@@ -1831,7 +1831,7 @@ macro_rules! uint_impl {
18311831
/// assert_eq!(100u8.wrapping_div(10), 10);
18321832
/// ```
18331833
#[stable(feature = "num_wrapping", since = "1.2.0")]
1834-
#[inline(always)]
1834+
#[inline]
18351835
pub fn wrapping_div(self, rhs: Self) -> Self {
18361836
self / rhs
18371837
}
@@ -1851,7 +1851,7 @@ macro_rules! uint_impl {
18511851
/// assert_eq!(100u8.wrapping_rem(10), 0);
18521852
/// ```
18531853
#[stable(feature = "num_wrapping", since = "1.2.0")]
1854-
#[inline(always)]
1854+
#[inline]
18551855
pub fn wrapping_rem(self, rhs: Self) -> Self {
18561856
self % rhs
18571857
}
@@ -1877,7 +1877,7 @@ macro_rules! uint_impl {
18771877
/// assert_eq!(180u8.wrapping_neg(), (127 + 1) - (180u8 - (127 + 1)));
18781878
/// ```
18791879
#[stable(feature = "num_wrapping", since = "1.2.0")]
1880-
#[inline(always)]
1880+
#[inline]
18811881
pub fn wrapping_neg(self) -> Self {
18821882
self.overflowing_neg().0
18831883
}
@@ -1902,7 +1902,7 @@ macro_rules! uint_impl {
19021902
/// assert_eq!(1u8.wrapping_shl(8), 1);
19031903
/// ```
19041904
#[stable(feature = "num_wrapping", since = "1.2.0")]
1905-
#[inline(always)]
1905+
#[inline]
19061906
pub fn wrapping_shl(self, rhs: u32) -> Self {
19071907
unsafe {
19081908
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
@@ -1929,7 +1929,7 @@ macro_rules! uint_impl {
19291929
/// assert_eq!(128u8.wrapping_shr(8), 128);
19301930
/// ```
19311931
#[stable(feature = "num_wrapping", since = "1.2.0")]
1932-
#[inline(always)]
1932+
#[inline]
19331933
pub fn wrapping_shr(self, rhs: u32) -> Self {
19341934
unsafe {
19351935
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)

‎src/libcore/num/wrapping.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! sh_impl_signed {
1919
impl Shl<$f> for Wrapping<$t> {
2020
type Output = Wrapping<$t>;
2121

22-
#[inline(always)]
22+
#[inline]
2323
fn shl(self, other: $f) -> Wrapping<$t> {
2424
if other < 0 {
2525
Wrapping(self.0.wrapping_shr((-other & self::shift_max::$t as $f) as u32))
@@ -31,7 +31,7 @@ macro_rules! sh_impl_signed {
3131

3232
#[stable(feature = "op_assign_traits", since = "1.8.0")]
3333
impl ShlAssign<$f> for Wrapping<$t> {
34-
#[inline(always)]
34+
#[inline]
3535
fn shl_assign(&mut self, other: $f) {
3636
*self = *self << other;
3737
}
@@ -41,7 +41,7 @@ macro_rules! sh_impl_signed {
4141
impl Shr<$f> for Wrapping<$t> {
4242
type Output = Wrapping<$t>;
4343

44-
#[inline(always)]
44+
#[inline]
4545
fn shr(self, other: $f) -> Wrapping<$t> {
4646
if other < 0 {
4747
Wrapping(self.0.wrapping_shl((-other & self::shift_max::$t as $f) as u32))
@@ -53,7 +53,7 @@ macro_rules! sh_impl_signed {
5353

5454
#[stable(feature = "op_assign_traits", since = "1.8.0")]
5555
impl ShrAssign<$f> for Wrapping<$t> {
56-
#[inline(always)]
56+
#[inline]
5757
fn shr_assign(&mut self, other: $f) {
5858
*self = *self >> other;
5959
}
@@ -67,15 +67,15 @@ macro_rules! sh_impl_unsigned {
6767
impl Shl<$f> for Wrapping<$t> {
6868
type Output = Wrapping<$t>;
6969

70-
#[inline(always)]
70+
#[inline]
7171
fn shl(self, other: $f) -> Wrapping<$t> {
7272
Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
7373
}
7474
}
7575

7676
#[stable(feature = "op_assign_traits", since = "1.8.0")]
7777
impl ShlAssign<$f> for Wrapping<$t> {
78-
#[inline(always)]
78+
#[inline]
7979
fn shl_assign(&mut self, other: $f) {
8080
*self = *self << other;
8181
}
@@ -85,15 +85,15 @@ macro_rules! sh_impl_unsigned {
8585
impl Shr<$f> for Wrapping<$t> {
8686
type Output = Wrapping<$t>;
8787

88-
#[inline(always)]
88+
#[inline]
8989
fn shr(self, other: $f) -> Wrapping<$t> {
9090
Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
9191
}
9292
}
9393

9494
#[stable(feature = "op_assign_traits", since = "1.8.0")]
9595
impl ShrAssign<$f> for Wrapping<$t> {
96-
#[inline(always)]
96+
#[inline]
9797
fn shr_assign(&mut self, other: $f) {
9898
*self = *self >> other;
9999
}
@@ -127,7 +127,7 @@ macro_rules! wrapping_impl {
127127
impl Add for Wrapping<$t> {
128128
type Output = Wrapping<$t>;
129129

130-
#[inline(always)]
130+
#[inline]
131131
fn add(self, other: Wrapping<$t>) -> Wrapping<$t> {
132132
Wrapping(self.0.wrapping_add(other.0))
133133
}
@@ -137,7 +137,7 @@ macro_rules! wrapping_impl {
137137

138138
#[stable(feature = "op_assign_traits", since = "1.8.0")]
139139
impl AddAssign for Wrapping<$t> {
140-
#[inline(always)]
140+
#[inline]
141141
fn add_assign(&mut self, other: Wrapping<$t>) {
142142
*self = *self + other;
143143
}
@@ -147,7 +147,7 @@ macro_rules! wrapping_impl {
147147
impl Sub for Wrapping<$t> {
148148
type Output = Wrapping<$t>;
149149

150-
#[inline(always)]
150+
#[inline]
151151
fn sub(self, other: Wrapping<$t>) -> Wrapping<$t> {
152152
Wrapping(self.0.wrapping_sub(other.0))
153153
}
@@ -157,7 +157,7 @@ macro_rules! wrapping_impl {
157157

158158
#[stable(feature = "op_assign_traits", since = "1.8.0")]
159159
impl SubAssign for Wrapping<$t> {
160-
#[inline(always)]
160+
#[inline]
161161
fn sub_assign(&mut self, other: Wrapping<$t>) {
162162
*self = *self - other;
163163
}
@@ -167,7 +167,7 @@ macro_rules! wrapping_impl {
167167
impl Mul for Wrapping<$t> {
168168
type Output = Wrapping<$t>;
169169

170-
#[inline(always)]
170+
#[inline]
171171
fn mul(self, other: Wrapping<$t>) -> Wrapping<$t> {
172172
Wrapping(self.0.wrapping_mul(other.0))
173173
}
@@ -177,7 +177,7 @@ macro_rules! wrapping_impl {
177177

178178
#[stable(feature = "op_assign_traits", since = "1.8.0")]
179179
impl MulAssign for Wrapping<$t> {
180-
#[inline(always)]
180+
#[inline]
181181
fn mul_assign(&mut self, other: Wrapping<$t>) {
182182
*self = *self * other;
183183
}
@@ -187,7 +187,7 @@ macro_rules! wrapping_impl {
187187
impl Div for Wrapping<$t> {
188188
type Output = Wrapping<$t>;
189189

190-
#[inline(always)]
190+
#[inline]
191191
fn div(self, other: Wrapping<$t>) -> Wrapping<$t> {
192192
Wrapping(self.0.wrapping_div(other.0))
193193
}
@@ -197,7 +197,7 @@ macro_rules! wrapping_impl {
197197

198198
#[stable(feature = "op_assign_traits", since = "1.8.0")]
199199
impl DivAssign for Wrapping<$t> {
200-
#[inline(always)]
200+
#[inline]
201201
fn div_assign(&mut self, other: Wrapping<$t>) {
202202
*self = *self / other;
203203
}
@@ -207,7 +207,7 @@ macro_rules! wrapping_impl {
207207
impl Rem for Wrapping<$t> {
208208
type Output = Wrapping<$t>;
209209

210-
#[inline(always)]
210+
#[inline]
211211
fn rem(self, other: Wrapping<$t>) -> Wrapping<$t> {
212212
Wrapping(self.0.wrapping_rem(other.0))
213213
}
@@ -217,7 +217,7 @@ macro_rules! wrapping_impl {
217217

218218
#[stable(feature = "op_assign_traits", since = "1.8.0")]
219219
impl RemAssign for Wrapping<$t> {
220-
#[inline(always)]
220+
#[inline]
221221
fn rem_assign(&mut self, other: Wrapping<$t>) {
222222
*self = *self % other;
223223
}
@@ -227,7 +227,7 @@ macro_rules! wrapping_impl {
227227
impl Not for Wrapping<$t> {
228228
type Output = Wrapping<$t>;
229229

230-
#[inline(always)]
230+
#[inline]
231231
fn not(self) -> Wrapping<$t> {
232232
Wrapping(!self.0)
233233
}
@@ -239,7 +239,7 @@ macro_rules! wrapping_impl {
239239
impl BitXor for Wrapping<$t> {
240240
type Output = Wrapping<$t>;
241241

242-
#[inline(always)]
242+
#[inline]
243243
fn bitxor(self, other: Wrapping<$t>) -> Wrapping<$t> {
244244
Wrapping(self.0 ^ other.0)
245245
}
@@ -249,7 +249,7 @@ macro_rules! wrapping_impl {
249249

250250
#[stable(feature = "op_assign_traits", since = "1.8.0")]
251251
impl BitXorAssign for Wrapping<$t> {
252-
#[inline(always)]
252+
#[inline]
253253
fn bitxor_assign(&mut self, other: Wrapping<$t>) {
254254
*self = *self ^ other;
255255
}
@@ -259,7 +259,7 @@ macro_rules! wrapping_impl {
259259
impl BitOr for Wrapping<$t> {
260260
type Output = Wrapping<$t>;
261261

262-
#[inline(always)]
262+
#[inline]
263263
fn bitor(self, other: Wrapping<$t>) -> Wrapping<$t> {
264264
Wrapping(self.0 | other.0)
265265
}
@@ -269,7 +269,7 @@ macro_rules! wrapping_impl {
269269

270270
#[stable(feature = "op_assign_traits", since = "1.8.0")]
271271
impl BitOrAssign for Wrapping<$t> {
272-
#[inline(always)]
272+
#[inline]
273273
fn bitor_assign(&mut self, other: Wrapping<$t>) {
274274
*self = *self | other;
275275
}
@@ -279,7 +279,7 @@ macro_rules! wrapping_impl {
279279
impl BitAnd for Wrapping<$t> {
280280
type Output = Wrapping<$t>;
281281

282-
#[inline(always)]
282+
#[inline]
283283
fn bitand(self, other: Wrapping<$t>) -> Wrapping<$t> {
284284
Wrapping(self.0 & other.0)
285285
}
@@ -289,7 +289,7 @@ macro_rules! wrapping_impl {
289289

290290
#[stable(feature = "op_assign_traits", since = "1.8.0")]
291291
impl BitAndAssign for Wrapping<$t> {
292-
#[inline(always)]
292+
#[inline]
293293
fn bitand_assign(&mut self, other: Wrapping<$t>) {
294294
*self = *self & other;
295295
}
@@ -298,7 +298,7 @@ macro_rules! wrapping_impl {
298298
#[stable(feature = "wrapping_neg", since = "1.10.0")]
299299
impl Neg for Wrapping<$t> {
300300
type Output = Self;
301-
#[inline(always)]
301+
#[inline]
302302
fn neg(self) -> Self {
303303
Wrapping(0) - self
304304
}

‎src/libcore/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
244244
/// assert_eq!(std::ptr::read(y), 12);
245245
/// }
246246
/// ```
247-
#[inline(always)]
247+
#[inline]
248248
#[stable(feature = "rust1", since = "1.0.0")]
249249
pub unsafe fn read<T>(src: *const T) -> T {
250250
let mut tmp: T = mem::uninitialized();
@@ -278,7 +278,7 @@ pub unsafe fn read<T>(src: *const T) -> T {
278278
/// assert_eq!(std::ptr::read_unaligned(y), 12);
279279
/// }
280280
/// ```
281-
#[inline(always)]
281+
#[inline]
282282
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
283283
pub unsafe fn read_unaligned<T>(src: *const T) -> T {
284284
let mut tmp: T = mem::uninitialized();

‎src/libcore/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ impl<'a, T> IntoIterator for &'a mut [T] {
11051105
}
11061106
}
11071107

1108-
#[inline(always)]
1108+
#[inline]
11091109
fn size_from_ptr<T>(_: *const T) -> usize {
11101110
mem::size_of::<T>()
11111111
}

‎src/libcore/str/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ unsafe fn from_raw_parts_mut<'a>(p: *mut u8, len: usize) -> &'a mut str {
369369
///
370370
/// assert_eq!("💖", sparkle_heart);
371371
/// ```
372-
#[inline(always)]
372+
#[inline]
373373
#[stable(feature = "rust1", since = "1.0.0")]
374374
pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
375375
mem::transmute(v)
@@ -381,7 +381,7 @@ pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
381381
/// See the immutable version, [`from_utf8_unchecked()`][fromutf8], for more information.
382382
///
383383
/// [fromutf8]: fn.from_utf8_unchecked.html
384-
#[inline(always)]
384+
#[inline]
385385
#[unstable(feature = "str_mut_extras", issue = "41119")]
386386
pub unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
387387
mem::transmute(v)
@@ -1380,7 +1380,7 @@ fn contains_nonascii(x: usize) -> bool {
13801380
/// returning `true` in that case, or, if it is invalid, `false` with
13811381
/// `iter` reset such that it is pointing at the first byte in the
13821382
/// invalid sequence.
1383-
#[inline(always)]
1383+
#[inline]
13841384
fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
13851385
let mut index = 0;
13861386
let len = v.len();

‎src/libcore/str/pattern.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ unsafe impl<'a, 'b> Searcher<'a> for StrSearcher<'a, 'b> {
668668
}
669669
}
670670

671-
#[inline(always)]
671+
#[inline]
672672
fn next_match(&mut self) -> Option<(usize, usize)> {
673673
match self.searcher {
674674
StrSearcherImpl::Empty(..) => {
@@ -936,7 +936,7 @@ impl TwoWaySearcher {
936936
bytes.iter().fold(0, |a, &b| (1 << (b & 0x3f)) | a)
937937
}
938938

939-
#[inline(always)]
939+
#[inline]
940940
fn byteset_contains(&self, byte: u8) -> bool {
941941
(self.byteset >> ((byte & 0x3f) as usize)) & 1 != 0
942942
}
@@ -946,7 +946,7 @@ impl TwoWaySearcher {
946946
// left to right. If v matches, we try to match u by scanning right to left.
947947
// How far we can jump when we encounter a mismatch is all based on the fact
948948
// that (u, v) is a critical factorization for the needle.
949-
#[inline(always)]
949+
#[inline]
950950
fn next<S>(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
951951
-> S::Output
952952
where S: TwoWayStrategy

0 commit comments

Comments
 (0)
Please sign in to comment.