mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 23:17:46 +00:00
factor::factor: Use u64::trailing_zero instead of iterated division
No significant performance impact (most of the time is spent elsewhere), but an easy and satisfying fix nevertheless.
This commit is contained in:
parent
a1b2522750
commit
bc11e57962
1 changed files with 4 additions and 3 deletions
|
@ -83,9 +83,10 @@ fn factor(mut n: u64) -> Factors {
|
||||||
return factors;
|
return factors;
|
||||||
}
|
}
|
||||||
|
|
||||||
while n % 2 == 0 {
|
let z = n.trailing_zeros();
|
||||||
n /= 2;
|
if z > 0 {
|
||||||
factors.push(2);
|
factors.add(2, z as u8);
|
||||||
|
n = n >> z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue