On Mon, 7 May 2012 12:35:27 +0100 Mark Dickinson <dicki...@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. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com