[Python-ideas] PEP 355 (overloading boolean operations) and chained comparisons

Raymond Hettinger raymond.hettinger at gmail.com
Thu Oct 20 02:16:29 CEST 2011


On Oct 19, 2011, at 3:25 PM, Greg Ewing wrote:

> What peephole optimisations are currently applied
> to boolean expressions?

Here's the comment from Python/peephole.c:

                /* Simplify conditional jump to conditional jump where the
                   result of the first test implies the success of a similar
                   test or the failure of the opposite test.
                   Arises in code like:
                   "if a and b:"
                   "if a or b:"
                   "a and b or c"
                   "(a and b) and c"
                   x:JUMP_IF_FALSE_OR_POP y   y:JUMP_IF_FALSE_OR_POP z
                      -->  x:JUMP_IF_FALSE_OR_POP z
                   x:JUMP_IF_FALSE_OR_POP y   y:JUMP_IF_TRUE_OR_POP z
                      -->  x:POP_JUMP_IF_FALSE y+3
                   where y+3 is the instruction following the second test.
                */

Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111019/6999918f/attachment.html>


More information about the Python-ideas mailing list