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:
pscott
2020-07-21 14:46:49 +02:00
committed by GitHub
parent ab82eb1c98
commit 046fda914a
73 changed files with 141 additions and 144 deletions
@@ -416,7 +416,7 @@ pub fn seq_phragmen<AccountId, R>(
n.load.n(),
n.budget,
c.approval_stake,
).unwrap_or(Bounded::max_value());
).unwrap_or_else(|_| Bounded::max_value());
let temp_d = n.load.d();
let temp = Rational128::from(temp_n, temp_d);
c.score = c.score.lazy_saturating_add(temp);
@@ -470,14 +470,14 @@ pub fn seq_phragmen<AccountId, R>(
n.load.n(),
)
// If result cannot fit in u128. Not much we can do about it.
.unwrap_or(Bounded::max_value());
.unwrap_or_else(|_| Bounded::max_value());
TryFrom::try_from(parts)
// If the result cannot fit into R::Inner. Defensive only. This can
// never happen. `desired_scale * e / n`, where `e / n < 1` always
// yields a value smaller than `desired_scale`, which will fit into
// R::Inner.
.unwrap_or(Bounded::max_value())
.unwrap_or_else(|_| Bounded::max_value())
} else {
// defensive only. Both edge and voter loads are built from
// scores, hence MUST have the same denominator.
@@ -362,11 +362,11 @@ fn reduce_all<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32
// create both.
let voter_node = tree
.entry(voter_id.clone())
.or_insert(Node::new(voter_id).into_ref())
.or_insert_with(|| Node::new(voter_id).into_ref())
.clone();
let target_node = tree
.entry(target_id.clone())
.or_insert(Node::new(target_id).into_ref())
.or_insert_with(|| Node::new(target_id).into_ref())
.clone();
// If one exists but the other one doesn't, or if both does not, then set the existing