On Mon, 7 May 2012 12:35:27 +0100 Mark Dickinson <dickinsm at gmail.com> wrote: > > Hmm. Very clever, but it's not obvious that that overflow check is > mathematically sound. As it turns out, the maths works provided that > PY_SSIZE_T_MAX isn't congruent to 4 modulo 5; since PY_SSIZE_T_MAX > will almost always be one less than a power of 2 and powers of 2 are > always congruent to 1, 2 or 4 modulo 5, we're safe. > > Is the gain from this kind of micro-optimization really worth the cost > of replacing obviously correct code with code whose correctness needs > several minutes of thought? Agreed that the original code is good enough. Dividing by 4 is fast, and this particular line of code is followed by a memory reallocation. In general, "clever" micro-optimizations that don't produce significant performance improvements should be avoided, IMHO :-) Regards Antoine.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4