This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients benjamin.peterson, brett.cannon, ncoghlan, rhettinger, serhiy.storchaka, yselivanov
Date 2017-05-29.06:58:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1496041116.54.0.344455983628.issue30501@psf.upfronthosting.co.za>
In-reply-to
Content
The peephole optimizer optimizes some boolean conditions. For example in "if not a:" it replaces UNARY_NOT+POP_JUMP_IF_FALSE with POP_JUMP_IF_TRUE, and in "if a and b:" it makes checking the boolean value of a only once. But it is unable to optimize more complex conditions, like "if not a and b:".

Proposed patch makes the compiler producing optimized code for conditions. It supports expressions with arbitrary complexity containing the "not" operator, the "and" and "or" binary operators, the "if" ternary operator, and chained comparisons, used as conditions in the ternary operator, in the "if", "while" and "assert" statements, and in generator expressions and comprehensions.

It would be possible to remove the part of the peepholer optimizer, but it is needed also for optimizing the "and" and "or" operators in non-boolean context. Doing this optimization in the compiler is possible but too cumbersome, it requires 3 times more code that in the proposed patch. May be I'll find the more general solution in future.
History
Date User Action Args
2017-05-29 06:58:36serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, rhettinger, ncoghlan, benjamin.peterson, yselivanov
2017-05-29 06:58:36serhiy.storchakasetmessageid: <1496041116.54.0.344455983628.issue30501@psf.upfronthosting.co.za>
2017-05-29 06:58:36serhiy.storchakalinkissue30501 messages
2017-05-29 06:58:35serhiy.storchakacreate