diff options
author | Abseil Team <absl-team@google.com> | 2020-02-08 01:54:07 (GMT) |
---|---|---|
committer | Mark Barolak <mbar@google.com> | 2020-02-11 20:49:53 (GMT) |
commit | 139fa202c9380740df625245f47128b24b21e5e6 (patch) | |
tree | 486e2020a9c713e00c6aa3faef6b0c3d2fc6c33a /googletest/samples/prime_tables.h | |
parent | 41b5f149ab306e96b5b2faf523505d75acffd98a (diff) | |
download | googletest-139fa202c9380740df625245f47128b24b21e5e6.zip googletest-139fa202c9380740df625245f47128b24b21e5e6.tar.gz googletest-139fa202c9380740df625245f47128b24b21e5e6.tar.bz2 |
Googletest export
Refactor function GetNextPrime so that the loop precondition is checked before
loop instead of during every loop run. Also by removing the loop condition,
it shows that the only exit from the loop is the return statement.
PiperOrigin-RevId: 293932783
Diffstat (limited to 'googletest/samples/prime_tables.h')
-rw-r--r-- | googletest/samples/prime_tables.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/googletest/samples/prime_tables.h b/googletest/samples/prime_tables.h index 72539bf..34002f3 100644 --- a/googletest/samples/prime_tables.h +++ b/googletest/samples/prime_tables.h @@ -66,11 +66,11 @@ class OnTheFlyPrimeTable : public PrimeTable { } int GetNextPrime(int p) const override { - for (int n = p + 1; n > 0; n++) { + if (p < 0) return -1; + + for (int n = p + 1;; n++) { if (IsPrime(n)) return n; } - - return -1; } }; |