From 418fd6175952c4147de24407d224b140c843b619 Mon Sep 17 00:00:00 2001 From: nicoo Date: Sun, 24 May 2020 15:41:23 +0200 Subject: [PATCH] factor::factor: Short-circuit the fallback to Pollard's rho When the remainder is smaller than the max. entry in the table, it is guaranteed to be prime. --- src/uu/factor/src/factor.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index 894c61c81..1e5b3bb8f 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -100,7 +100,11 @@ fn factor(mut n: u64) -> Factors { let (f, n) = table::factor(n); factors *= f; - factors *= rho::factor(n); + + if n >= table::NEXT_PRIME { + factors *= rho::factor(n); + } + factors }