declone and close the door (#12035)

* declone and close the door

* cargo fmt

* remove brackets
This commit is contained in:
Squirrel
2022-08-15 20:38:36 +01:00
committed by GitHub
parent 9c2a2495fe
commit a68a80fbae
72 changed files with 344 additions and 512 deletions
@@ -92,7 +92,7 @@ where
.into_iter()
.enumerate()
.map(|(idx, who)| {
c_idx_cache.insert(who.clone(), idx);
c_idx_cache.insert(who, idx);
_Candidate { who, ..Default::default() }
})
.collect::<Vec<_Candidate<A>>>();
@@ -103,7 +103,7 @@ where
for v in votes {
if let Some(idx) = c_idx_cache.get(&v) {
candidates[*idx].approval_stake = candidates[*idx].approval_stake + voter_stake;
edges.push(_Edge { who: v.clone(), candidate_index: *idx, ..Default::default() });
edges.push(_Edge { who: v, candidate_index: *idx, ..Default::default() });
}
}
_Voter { who, edges, budget: voter_stake, load: 0f64 }
@@ -143,21 +143,21 @@ where
}
}
elected_candidates.push((winner.who.clone(), winner.approval_stake as ExtendedBalance));
elected_candidates.push((winner.who, winner.approval_stake as ExtendedBalance));
} else {
break
}
}
for n in &mut voters {
let mut assignment = (n.who.clone(), vec![]);
let mut assignment = (n.who, vec![]);
for e in &mut n.edges {
if let Some(c) =
elected_candidates.iter().cloned().map(|(c, _)| c).find(|c| *c == e.who)
{
if c != n.who {
let ratio = e.load / n.load;
assignment.1.push((e.who.clone(), ratio));
assignment.1.push((e.who, ratio));
}
}
}
@@ -321,7 +321,7 @@ pub(crate) fn run_and_compare<Output: PerThing128, FS>(
candidates.clone(),
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -368,7 +368,7 @@ pub(crate) fn build_support_map_float(
let mut supports = <_SupportMap<AccountId>>::new();
result.winners.iter().map(|(e, _)| (e, stake_of(e) as f64)).for_each(|(e, s)| {
let item = _Support { own: s, total: s, ..Default::default() };
supports.insert(e.clone(), item);
supports.insert(*e, item);
});
for (n, assignment) in result.assignments.iter_mut() {
@@ -377,7 +377,7 @@ pub(crate) fn build_support_map_float(
let other_stake = nominator_stake * *r;
if let Some(support) = supports.get_mut(c) {
support.total = support.total + other_stake;
support.others.push((n.clone(), other_stake));
support.others.push((*n, other_stake));
}
*r = other_stake;
}
@@ -481,7 +481,7 @@ mod tests {
assert_eq!(
candidates
.iter()
.map(|c| (c.borrow().who.clone(), c.borrow().elected, c.borrow().backed_stake))
.map(|c| (c.borrow().who, c.borrow().elected, c.borrow().backed_stake))
.collect::<Vec<_>>(),
vec![(10, false, 0), (20, true, 15), (30, false, 0), (40, true, 15)],
);
@@ -233,7 +233,7 @@ fn phragmen_poc_works() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -289,7 +289,7 @@ fn phragmen_poc_works_with_balancing() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
Some(config),
)
@@ -376,7 +376,7 @@ fn phragmen_accuracy_on_large_scale_only_candidates() {
candidates.clone(),
auto_generate_self_voters(&candidates)
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -407,7 +407,7 @@ fn phragmen_accuracy_on_large_scale_voters_and_candidates() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -439,7 +439,7 @@ fn phragmen_accuracy_on_small_scale_self_vote() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -469,7 +469,7 @@ fn phragmen_accuracy_on_small_scale_no_self_vote() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -505,7 +505,7 @@ fn phragmen_large_scale_test() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -532,7 +532,7 @@ fn phragmen_large_scale_test_2() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -601,7 +601,7 @@ fn elect_has_no_entry_barrier() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -622,7 +622,7 @@ fn phragmen_self_votes_should_be_kept() {
candidates,
voters
.iter()
.map(|(ref v, ref vs)| (v.clone(), stake_of(v), vs.clone()))
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>(),
None,
)
@@ -872,30 +872,15 @@ mod score {
let claim =
[12488167277027543u128, 5559266368032409496, 118700736389524721358337889258988054];
assert_eq!(
is_score_better(claim.clone(), initial.clone(), Perbill::from_rational(1u32, 10_000),),
true,
);
assert_eq!(is_score_better(claim, initial, Perbill::from_rational(1u32, 10_000),), true,);
assert_eq!(
is_score_better(claim.clone(), initial.clone(), Perbill::from_rational(2u32, 10_000),),
true,
);
assert_eq!(is_score_better(claim, initial, Perbill::from_rational(2u32, 10_000),), true,);
assert_eq!(
is_score_better(claim.clone(), initial.clone(), Perbill::from_rational(3u32, 10_000),),
true,
);
assert_eq!(is_score_better(claim, initial, Perbill::from_rational(3u32, 10_000),), true,);
assert_eq!(
is_score_better(claim.clone(), initial.clone(), Perbill::from_rational(4u32, 10_000),),
true,
);
assert_eq!(is_score_better(claim, initial, Perbill::from_rational(4u32, 10_000),), true,);
assert_eq!(
is_score_better(claim.clone(), initial.clone(), Perbill::from_rational(5u32, 10_000),),
false,
);
assert_eq!(is_score_better(claim, initial, Perbill::from_rational(5u32, 10_000),), false,);
}
#[test]