mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Optimize bool|1, bool&1 when possible.
a & 1 is always a, if a is boolean. a | 1 is always 1, if a is boolean, but it can only be optimized out if a is side effect-free.
This commit is contained in:
parent
3f61e6f7bf
commit
44e0db96d2
1 changed files with 4 additions and 2 deletions
|
@ -824,13 +824,15 @@ class foldconst(object):
|
|||
|
||||
if child[b]['nt'] == 'CONST':
|
||||
val = child[b]['value']
|
||||
if val == 0 and nt == '|' or val == -1 and nt == '&':
|
||||
if nt == '|' and val == 0 or nt == '&' and (val == -1 or val == 1 and self.IsBool(child[a])):
|
||||
# a|0 -> a
|
||||
# a&-1 -> a
|
||||
# a&1 -> a if a is boolean
|
||||
parent[index] = child[a]
|
||||
return
|
||||
if val == -1 and nt == '|' or val == 0 and nt == '&':
|
||||
if nt == '|' and (val == -1 or val == 1 and self.IsBool(child[a])) or nt == '&' and val == 0:
|
||||
# a|-1 -> -1 if a is SEF
|
||||
# a|1 -> 1 if a is bool and SEF
|
||||
# a&0 -> 0 if a is SEF
|
||||
if 'SEF' in child[a]:
|
||||
parent[index] = child[b]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue