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.
This commit is contained in:
Mazdak Farrokhzad 2019-10-13 19:17:07 +02:00 committed by GitHub
commit f0f5e779bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()