factor: Derecursify and refactor
~7% slowdown, paves the way for upcoming improvements
@@ -14,7 +14,8 @@ use crate::Factors;
include!(concat!(env!("OUT_DIR"), "/prime_table.rs"));
-pub(crate) fn factor(mut num: u64, mut factors: Factors) -> (Factors, u64) {
+pub(crate) fn factor(n: &mut u64, factors: &mut Factors) {
+ let mut num = *n;
for &(prime, inv, ceil) in P_INVS_U64 {
if num == 1 {
break;
@@ -42,5 +43,5 @@ pub(crate) fn factor(mut num: u64, mut factors: Factors) -> (Factors, u64) {
}
}
- (factors, num)
+ *n = num;
}
