mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Improve overall performance (#6699)
* Improve overall performance * Clean up code Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove needless :: Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove needless :: Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -84,7 +84,7 @@ pub trait FixedPointNumber:
|
||||
fn saturating_from_integer<N: FixedPointOperand>(int: N) -> Self {
|
||||
let mut n: I129 = int.into();
|
||||
n.value = n.value.saturating_mul(Self::DIV.saturated_into());
|
||||
Self::from_inner(from_i129(n).unwrap_or(to_bound(int, 0)))
|
||||
Self::from_inner(from_i129(n).unwrap_or_else(|| to_bound(int, 0)))
|
||||
}
|
||||
|
||||
/// Creates `self` from an integer number `int`.
|
||||
@@ -101,7 +101,7 @@ pub trait FixedPointNumber:
|
||||
if d == D::zero() {
|
||||
panic!("attempt to divide by zero")
|
||||
}
|
||||
Self::checked_from_rational(n, d).unwrap_or(to_bound(n, d))
|
||||
Self::checked_from_rational(n, d).unwrap_or_else(|| to_bound(n, d))
|
||||
}
|
||||
|
||||
/// Creates `self` from a rational number. Equal to `n / d`.
|
||||
@@ -137,7 +137,7 @@ pub trait FixedPointNumber:
|
||||
///
|
||||
/// Returns `N::min` or `N::max` if the result does not fit in `N`.
|
||||
fn saturating_mul_int<N: FixedPointOperand>(self, n: N) -> N {
|
||||
self.checked_mul_int(n).unwrap_or(to_bound(self.into_inner(), n))
|
||||
self.checked_mul_int(n).unwrap_or_else(|| to_bound(self.into_inner(), n))
|
||||
}
|
||||
|
||||
/// Checked division for integer type `N`. Equal to `self / d`.
|
||||
@@ -160,7 +160,7 @@ pub trait FixedPointNumber:
|
||||
if d == N::zero() {
|
||||
panic!("attempt to divide by zero")
|
||||
}
|
||||
self.checked_div_int(d).unwrap_or(to_bound(self.into_inner(), d))
|
||||
self.checked_div_int(d).unwrap_or_else(|| to_bound(self.into_inner(), d))
|
||||
}
|
||||
|
||||
/// Saturating multiplication for integer type `N`, adding the result back.
|
||||
@@ -183,7 +183,7 @@ pub trait FixedPointNumber:
|
||||
if inner >= Self::Inner::zero() {
|
||||
self
|
||||
} else {
|
||||
Self::from_inner(inner.checked_neg().unwrap_or(Self::Inner::max_value()))
|
||||
Self::from_inner(inner.checked_neg().unwrap_or_else(|| Self::Inner::max_value()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ impl<N: FixedPointOperand> From<N> for I129 {
|
||||
if n < N::zero() {
|
||||
let value: u128 = n.checked_neg()
|
||||
.map(|n| n.unique_saturated_into())
|
||||
.unwrap_or(N::max_value().unique_saturated_into().saturating_add(1));
|
||||
.unwrap_or_else(|| N::max_value().unique_saturated_into().saturating_add(1));
|
||||
I129 { value, negative: true }
|
||||
} else {
|
||||
I129 { value: n.unique_saturated_into(), negative: false }
|
||||
@@ -399,7 +399,7 @@ macro_rules! implement_fixed {
|
||||
}
|
||||
|
||||
fn saturating_mul(self, rhs: Self) -> Self {
|
||||
self.checked_mul(&rhs).unwrap_or(to_bound(self.0, rhs.0))
|
||||
self.checked_mul(&rhs).unwrap_or_else(|| to_bound(self.0, rhs.0))
|
||||
}
|
||||
|
||||
fn saturating_pow(self, exp: usize) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user