On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft <r...@freenet.co.uk> wrote:
> mk wrote in news:mailman.915.1259064240.2873.python-l...@python.org in
> comp.lang.python:
>
>>
>> def pythonic():
>
>> def unpythonic():
>
>
>> Decidedly counterintuitive: are there special optimizations for "if
>> nonevar:" type of statements in cpython implementation?
>>
>
> from dis import dis
>
> dis( unpythonic )
>
> 18          31 LOAD_FAST                0 (nonevar)
>             34 LOAD_CONST               0 (None)
>             37 COMPARE_OP               9 (is not)
>             40 JUMP_IF_FALSE            4 (to 47)
>
> dis( pythonic )
>
> 11          31 LOAD_FAST                0 (nonevar)
>             34 JUMP_IF_FALSE            4 (to 41)

In other words, CPython doesn't happen to optimize `if nonevar is not
None` as much as it theoretically could (which would essentially
require a JUMP_IF_NONE opcode). Since CPython isn't known for doing
fancy optimizations, this isn't surprising.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to