Subject: | Primes() step j += 2*i for less work |

Date: | Sat, 06 Nov 2010 06:38:29 +1100 |

To: | bug-Bit-Vector@rt.cpan.org |

From: | Kevin Ryde <user42@zip.com.au> |

In Bit::Vector 7.1 BitVector_Primes(), as an optimization I wonder if
the "j" loop could increment by "j += 2*i" instead of "j += i". The
even numbers are already cleared by the 0xAAAA initializer are they?,
leaving only odd multiples of i needing attention.
Not sure if 2*i would risk overflow if bits==2^32-1, or near there, or
make more big sizes where it might overflow. Perhaps the loop condition
would be j <= bits-2*i before incrementing, with bits-2*i itself not
underflowing because i <= sqrt(bits) so bits >= 2*i ... if that sounds
right.