[Python-Dev] check for PyUnicode_READY look backwards (original) (raw)

Scott Dial scott+python-dev at scottdial.com
Sun Oct 16 06:12:04 CEST 2011


On 10/7/2011 7:13 PM, Terry Reedy wrote:

On 10/7/2011 10:06 AM, Nick Coghlan wrote:

FWIW, I don't mind whether it's "< 0" or "== -1", so long as there's a comparison there to kick my brain out of Python boolean logic mode. Is there any speed difference (on common x86/64 processors and compilers)? I would expect that '< 0' should be optimized to just check the sign bit and 'if n < 0' to 'load n; jump-non-negative'.

There are several different ways to express those operators depending on the context. If "n" is worth moving into a register, then "<0" will get to use a "test" and it's fewer instruction bytes than a "cmp", but otherwise, it is no better. So, there is a very special case where "<0" is better, but I think you'd be hard-pressed to measure it against the noise.

-- Scott Dial scott at scottdial.com



More information about the Python-Dev mailing list