summaryrefslogtreecommitdiffstats
path: root/googletest/samples
diff options
context:
space:
mode:
authormisterg <misterg@google.com>2018-01-02 19:42:09 (GMT)
committermisterg <misterg@google.com>2018-01-02 19:42:09 (GMT)
commite7734fb80cac5dd1f7c9845d5530d80b664a9f3e (patch)
tree7c74782876b29741b3105b5ff419a897b76cb1cf /googletest/samples
parent1c2f1907047216654599b0057df49d21a2c1400a (diff)
downloadgoogletest-e7734fb80cac5dd1f7c9845d5530d80b664a9f3e.zip
googletest-e7734fb80cac5dd1f7c9845d5530d80b664a9f3e.tar.gz
googletest-e7734fb80cac5dd1f7c9845d5530d80b664a9f3e.tar.bz2
OSS Sync, cl 163329677refs/pull/1376/head
Diffstat (limited to 'googletest/samples')
-rw-r--r--googletest/samples/prime_tables.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/googletest/samples/prime_tables.h b/googletest/samples/prime_tables.h
index 92ce16a..55a3b44 100644
--- a/googletest/samples/prime_tables.h
+++ b/googletest/samples/prime_tables.h
@@ -103,11 +103,15 @@ class PreCalculatedPrimeTable : public PrimeTable {
::std::fill(is_prime_, is_prime_ + is_prime_size_, true);
is_prime_[0] = is_prime_[1] = false;
- for (int i = 2; i <= max; i++) {
+ // Checks every candidate for prime number (we know that 2 is the only even
+ // prime).
+ for (int i = 2; i*i <= max; i += i%2+1) {
if (!is_prime_[i]) continue;
// Marks all multiples of i (except i itself) as non-prime.
- for (int j = 2*i; j <= max; j += i) {
+ // We are starting here from i-th multiplier, because all smaller
+ // complex numbers were already marked.
+ for (int j = i*i; j <= max; j += i) {
is_prime_[j] = false;
}
}