aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-24 09:04:41 +0200
committerAndreas Grois <andi@grois.info>2022-10-24 09:04:41 +0200
commit6b36d6396915181d38598928e35a20cf2308c5aa (patch)
tree614ad6917f07cd92c7aa5477ab123d786a1b84ed /src
parentcb219708923df26e0efc0ce172e1be7414287fe2 (diff)
Improve long division performance.
In PasswordMaker, the numbers that are fed into long division can only decrease. Therefore, skipping leading zeros is a rather reasonable improvement.
Diffstat (limited to 'src')
-rw-r--r--src/passwordmaker/base_conversion/remainders_impl.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/passwordmaker/base_conversion/remainders_impl.rs b/src/passwordmaker/base_conversion/remainders_impl.rs
index 7bc6c0e..8f0a7f9 100644
--- a/src/passwordmaker/base_conversion/remainders_impl.rs
+++ b/src/passwordmaker/base_conversion/remainders_impl.rs
@@ -13,7 +13,7 @@ impl<const N : usize> Division<usize> for [u32;N] {
//uses mutation, because why not? self is owned after all :D
let divisor : UsizeAndFour = *divisor as UsizeAndFour;
- let remainder = self.iter_mut().fold(0 as UsizeAndFour,|carry, current| {
+ let remainder = self.iter_mut().skip_while(|x| **x == 0).fold(0 as UsizeAndFour,|carry, current| {
debug_assert_eq!(carry, carry & (usize::MAX as UsizeAndFour)); //carry has to be lower than divisor, and divisor is usize.
let carry_shifted = carry << 32;
let dividend = (carry_shifted) + (*current as UsizeAndFour);