summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-02-08 01:54:07 (GMT)
committerMark Barolak <mbar@google.com>2020-02-11 20:49:53 (GMT)
commit139fa202c9380740df625245f47128b24b21e5e6 (patch)
tree486e2020a9c713e00c6aa3faef6b0c3d2fc6c33a /googletest
parent41b5f149ab306e96b5b2faf523505d75acffd98a (diff)
downloadgoogletest-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')
-rw-r--r--googletest/samples/prime_tables.h6
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;
}
};