diff options
| author | bors <bors@rust-lang.org> | 2023-04-30 07:43:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-30 07:43:18 +0000 |
| commit | c1bb0e09116c725766f5fa6b4a7ddfef28ef7e96 (patch) | |
| tree | 273ba0918fc244f50ff1f48b9ba306418aeeda30 | |
| parent | d3edfd18c790971c77845bfc1a2be4f9281c5416 (diff) | |
| parent | 8857cc2131e2f09bcb44c8867b6e6a50d9b4ae32 (diff) | |
| download | rust-c1bb0e09116c725766f5fa6b4a7ddfef28ef7e96.tar.gz rust-c1bb0e09116c725766f5fa6b4a7ddfef28ef7e96.zip | |
Auto merge of #110935 - scottmcm:always-ord, r=Mark-Simulacrum
`inline(always)` for `lt`/`le`/`ge`/`gt` on integers and floats
I happened to notice one of these not getting inlined as part of `Range::next` in <https://rust.godbolt.org/z/4WKWWxj1G>
```rust
bb1: {
StorageLive(_5);
_6 = &mut _4;
StorageLive(_21);
StorageLive(_14);
StorageLive(_15);
_15 = &((*_6).0: usize);
StorageLive(_16);
_16 = &((*_6).1: usize);
_14 = <usize as PartialOrd>::lt(move _15, move _16) -> bb7;
}
```
So since a call for something that's just one instruction is never the right choice, `#[inline(always)]` seems appropriate, like we have it on things like the rotate methods on integers.
| -rw-r--r-- | library/core/src/cmp.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 87ec35c040f..48b127716f5 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -1321,13 +1321,13 @@ mod impls { (true, true) => Some(Equal), } } - #[inline] + #[inline(always)] fn lt(&self, other: &$t) -> bool { (*self) < (*other) } - #[inline] + #[inline(always)] fn le(&self, other: &$t) -> bool { (*self) <= (*other) } - #[inline] + #[inline(always)] fn ge(&self, other: &$t) -> bool { (*self) >= (*other) } - #[inline] + #[inline(always)] fn gt(&self, other: &$t) -> bool { (*self) > (*other) } } )*) @@ -1359,13 +1359,13 @@ mod impls { fn partial_cmp(&self, other: &$t) -> Option<Ordering> { Some(self.cmp(other)) } - #[inline] + #[inline(always)] fn lt(&self, other: &$t) -> bool { (*self) < (*other) } - #[inline] + #[inline(always)] fn le(&self, other: &$t) -> bool { (*self) <= (*other) } - #[inline] + #[inline(always)] fn ge(&self, other: &$t) -> bool { (*self) >= (*other) } - #[inline] + #[inline(always)] fn gt(&self, other: &$t) -> bool { (*self) > (*other) } } |
