solipsis at pitrou
May 7, 2012, 9:38 AM
Post #5 of 7
On Mon, 7 May 2012 12:35:27 +0100
Re: [Python-checkins] cpython: Issue #14716: Change integer overflow check in unicode_writer_prepare()
[In reply to]
Mark Dickinson <dickinsm [at] gmail> 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 :-)
Python-Dev mailing list
Python-Dev [at] python