Skip to content
Snippets Groups Projects
Commit 370f31a2 authored by Éloïs's avatar Éloïs
Browse files

perf(claim_uds): remove one comparison per reeval (!85)

* perf(claim_uds): remove one comparison per reeval
parent e6be6a09
No related branches found
No related tags found
1 merge request!85perf(claim_uds): remove one comparison per reeval
......@@ -26,12 +26,15 @@ pub(super) fn compute_claim_uds<Balance: AtLeast32BitUnsigned>(
let mut total_amount = Zero::zero();
let mut total_count = 0;
for (ud_index, ud_amount) in past_reevals.rev() {
let count = current_ud_index - core::cmp::max(ud_index, first_ud_index);
total_amount += Balance::from(count) * ud_amount;
total_count += count;
if ud_index <= first_ud_index {
let count = current_ud_index - first_ud_index;
total_amount += Balance::from(count) * ud_amount;
total_count += count;
break;
} else {
let count = current_ud_index - ud_index;
total_amount += Balance::from(count) * ud_amount;
total_count += count;
current_ud_index = ud_index;
}
}
......
......@@ -76,7 +76,7 @@ impl<T: frame_system::Config> pallet_universal_dividend::WeightInfo for WeightIn
fn claim_uds(n: u32) -> Weight {
(1_228_876_000 as Weight)
// Standard Error: 958_000
.saturating_add((7_709_000 as Weight).saturating_mul(n as Weight))
.saturating_add((7_551_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment