[Python-Dev] check for PyUnicode_READY look backwards (original) (raw)
Terry Reedy tjreedy at udel.edu
Sat Oct 8 01:13:10 CEST 2011
- Previous message: [Python-Dev] check for PyUnicode_READY look backwards
- Next message: [Python-Dev] check for PyUnicode_READY look backwards
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/7/2011 10:06 AM, Nick Coghlan wrote:
On Fri, Oct 7, 2011 at 9:21 AM, "Martin v. Löwis"<martin at v.loewis.de> wrote:
> if (!PyUnicodeREADY(foo)) is not better, also because of
PyUnicodeISREADY(foo). I prefer PyUnicodeISREADY(foo)< 0 over PyUnicodeISREADY(foo) == -1.
Ok, so feel free to replace all == -1 tests with< 0 tests as well. I'll point out that the test for -1 is also widespread in Python, e.g. when checking return values from PyObjectSetAttrString, BaseExceptioninit, PyThreadcreatekey, PyObjectDelAttrString, etc. 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'.
-- Terry Jan Reedy
- Previous message: [Python-Dev] check for PyUnicode_READY look backwards
- Next message: [Python-Dev] check for PyUnicode_READY look backwards
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]