by XJ6 · 7y ago · 0 comments
If the last number generated is even, it will still appear in the result set in the new code, and not in the old code.
howmany -= (val bitand 1);
But that might complicate the benchmark.Coincidentally, this was the subject of the first Stack Overflow question Bjarne addressed in an interview the other day:
https://stackoverflow.com/questions/11227809/why-is-processi...
Here, trying to access out[index-1] would error.
Yes, you could then guard against that of course, but then that's even more code to maintain.
If this code is a critical hot-path then sure, micro-optimizations can make sense but doing so without over-commenting and a rigorous test suite to catch introduced bugs is a recipe for disaster.
If only the function had a unit test to catch such bugs