classification
Title: boolop constant checking for if/while
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Stephen.Tu, ZackerySpytz, benjamin.peterson, brett.cannon, georg.brandl, ncoghlan, nedbat
Priority: normal Keywords: patch

Created on 2013-04-13 17:17 by Stephen.Tu, last changed 2020-01-11 06:57 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
constcheck.patch Stephen.Tu, 2013-04-13 17:17 review
Messages (3)
msg186767 - (view) Author: Stephen Tu (Stephen.Tu) * Date: 2013-04-13 17:17
Here's a simple patch to optimize away constant boolean conjunctions/disjunctions. for example:

def foo():
    if 1 and 0:
        print("hi")

now disassembles into:
  7           0 LOAD_CONST               0 (None) 
              3 RETURN_VALUE 

while I realize more general techniques for achieving this have been proposed (ie http://bugs.python.org/issue1346238), this is a very simple, self-contained patch.
msg187383 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2013-04-19 19:10
Thank you for the patch. However, I don't think such "optimizations" are particularly useful.
msg359785 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-01-11 06:47
I think this issue should be closed.
History
Date User Action Args
2020-01-11 06:57:03benjamin.petersonsetstatus: open -> closed
resolution: rejected
stage: resolved
2020-01-11 06:47:52ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg359785
2013-04-19 19:10:21benjamin.petersonsetmessages: + msg187383
2013-04-19 19:02:38terry.reedysetnosy: + brett.cannon, georg.brandl, ncoghlan, benjamin.peterson
2013-04-13 17:26:22nedbatsetnosy: + nedbat
2013-04-13 17:17:57Stephen.Tucreate