about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-10-13 19:17:07 +0200
committerGitHub <noreply@github.com>2019-10-13 19:17:07 +0200
commitf0f5e779bc8f16406d7022e08da647d94cc30847 (patch)
tree518ab649339ac7650ae014fb62e118d4d7db73ef
parent2a9c79107696580c703d015ebc8aab008da82899 (diff)
parent57aae75ce39de12f1af8d33d2836db59f7269ed2 (diff)
downloadrust-f0f5e779bc8f16406d7022e08da647d94cc30847.tar.gz
rust-f0f5e779bc8f16406d7022e08da647d94cc30847.zip
Rollup merge of #65312 - tspiteri:signed-sat-mul, r=dtolnay
improve performance of signed saturating_mul

Reciprocal throughput is improved from 2.3 to 1.7. https://godbolt.org/z/ROMiX6

Fixes #65309.
-rw-r--r--src/libcore/num/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index ebde82de834..998c8f81652 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -1058,7 +1058,7 @@ $EndFeature, "
             #[inline]
             pub fn saturating_mul(self, rhs: Self) -> Self {
                 self.checked_mul(rhs).unwrap_or_else(|| {
-                    if (self < 0 && rhs < 0) || (self > 0 && rhs > 0) {
+                    if (self < 0) == (rhs < 0) {
                         Self::max_value()
                     } else {
                         Self::min_value()