Skip to content

Commit 363b20e

Browse files
Always inline arithmetic operators
In release mode, this has no effect, as they're inlined anyway, but in debug mode LLVM otherwise lowers these to a call instruction -- much more expensive than the inlined version.
1 parent 166c49d commit 363b20e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/libcore/ops/arith.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ macro_rules! add_impl {
9595
impl Add for $t {
9696
type Output = $t;
9797

98-
#[inline]
9998
#[rustc_inherit_overflow_checks]
99+
#[inline(always)]
100100
fn add(self, other: $t) -> $t { self + other }
101101
}
102102

@@ -193,7 +193,7 @@ macro_rules! sub_impl {
193193
impl Sub for $t {
194194
type Output = $t;
195195

196-
#[inline]
196+
#[inline(always)]
197197
#[rustc_inherit_overflow_checks]
198198
fn sub(self, other: $t) -> $t { self - other }
199199
}
@@ -313,7 +313,7 @@ macro_rules! mul_impl {
313313
impl Mul for $t {
314314
type Output = $t;
315315

316-
#[inline]
316+
#[inline(always)]
317317
#[rustc_inherit_overflow_checks]
318318
fn mul(self, other: $t) -> $t { self * other }
319319
}
@@ -439,7 +439,7 @@ macro_rules! div_impl_integer {
439439
impl Div for $t {
440440
type Output = $t;
441441

442-
#[inline]
442+
#[inline(always)]
443443
fn div(self, other: $t) -> $t { self / other }
444444
}
445445

@@ -455,7 +455,7 @@ macro_rules! div_impl_float {
455455
impl Div for $t {
456456
type Output = $t;
457457

458-
#[inline]
458+
#[inline(always)]
459459
fn div(self, other: $t) -> $t { self / other }
460460
}
461461

@@ -524,7 +524,7 @@ macro_rules! rem_impl_integer {
524524
impl Rem for $t {
525525
type Output = $t;
526526

527-
#[inline]
527+
#[inline(always)]
528528
fn rem(self, other: $t) -> $t { self % other }
529529
}
530530

@@ -556,7 +556,7 @@ macro_rules! rem_impl_float {
556556
impl Rem for $t {
557557
type Output = $t;
558558

559-
#[inline]
559+
#[inline(always)]
560560
fn rem(self, other: $t) -> $t { self % other }
561561
}
562562

@@ -624,7 +624,7 @@ macro_rules! neg_impl_core {
624624
impl Neg for $t {
625625
type Output = $t;
626626

627-
#[inline]
627+
#[inline(always)]
628628
#[rustc_inherit_overflow_checks]
629629
fn neg(self) -> $t { let $id = self; $body }
630630
}
@@ -693,7 +693,7 @@ macro_rules! add_assign_impl {
693693
($($t:ty)+) => ($(
694694
#[stable(feature = "op_assign_traits", since = "1.8.0")]
695695
impl AddAssign for $t {
696-
#[inline]
696+
#[inline(always)]
697697
#[rustc_inherit_overflow_checks]
698698
fn add_assign(&mut self, other: $t) { *self += other }
699699
}
@@ -749,7 +749,7 @@ macro_rules! sub_assign_impl {
749749
($($t:ty)+) => ($(
750750
#[stable(feature = "op_assign_traits", since = "1.8.0")]
751751
impl SubAssign for $t {
752-
#[inline]
752+
#[inline(always)]
753753
#[rustc_inherit_overflow_checks]
754754
fn sub_assign(&mut self, other: $t) { *self -= other }
755755
}
@@ -796,7 +796,7 @@ macro_rules! mul_assign_impl {
796796
($($t:ty)+) => ($(
797797
#[stable(feature = "op_assign_traits", since = "1.8.0")]
798798
impl MulAssign for $t {
799-
#[inline]
799+
#[inline(always)]
800800
#[rustc_inherit_overflow_checks]
801801
fn mul_assign(&mut self, other: $t) { *self *= other }
802802
}
@@ -843,7 +843,7 @@ macro_rules! div_assign_impl {
843843
($($t:ty)+) => ($(
844844
#[stable(feature = "op_assign_traits", since = "1.8.0")]
845845
impl DivAssign for $t {
846-
#[inline]
846+
#[inline(always)]
847847
fn div_assign(&mut self, other: $t) { *self /= other }
848848
}
849849

@@ -893,7 +893,7 @@ macro_rules! rem_assign_impl {
893893
($($t:ty)+) => ($(
894894
#[stable(feature = "op_assign_traits", since = "1.8.0")]
895895
impl RemAssign for $t {
896-
#[inline]
896+
#[inline(always)]
897897
fn rem_assign(&mut self, other: $t) { *self %= other }
898898
}
899899

0 commit comments

Comments
 (0)