mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Add IfElseSwap option
This enables an option that was being done unconditionally: to swap the `if` and `else` branches if the condition is shorter when negated. Enabled by default.
This commit is contained in:
parent
e62b5ffcb6
commit
08c429f22b
8 changed files with 44 additions and 17 deletions
|
@ -1796,7 +1796,7 @@ class foldconst(object):
|
|||
self.FoldTree(child, 2)
|
||||
self.FoldStmt(child, 2)
|
||||
# Check if it makes sense to swap if and else branches
|
||||
if not child[2].SEF:
|
||||
if self.ifelseswap and not child[2].SEF:
|
||||
# Check if we can gain something by negating the
|
||||
# expression.
|
||||
# Swap 'if' and 'else' branch when the condition has
|
||||
|
|
|
@ -68,6 +68,7 @@ class optimizer(foldconst, renamer, deadcode, lastpass):
|
|||
self.shrinknames = 'shrinknames' in options
|
||||
|
||||
self.constfold = 'constfold' in options
|
||||
self.ifelseswap = 'ifelseswap' in options
|
||||
self.optlistlength = 'listlength' in options
|
||||
self.optlistadd = 'listadd' in options
|
||||
self.dcr = 'dcr' in options
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue