This is of course an optimization which is hyper specific and in fact near useless in practice.<p>Converting an awful algorithm into a superior form (from O(N) to O(1)) is a neat trick, but obviously can only apply if:
- Such an algorithm can be easily detected by the Compiler and there is actually a replacement algorithm which does <i>exactly</i> the same thing within the defined behavior. These cases are very rare.
- The programmer is unable or unwilling to identify the optimization, which in most cases means he does not understand his algorithm well or does not care about performance.<p>Just as an example this substitutions CAN NOT be applied if you replace ints with floats. Of course the O(1) algorithm is still generally preferable in that case a Compiler will never help you with that if you use floats.