mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Make IsBool smarter when finding whether an expression is boolean.
It was failing with a && b && c where a, b, c were known to be bools. It managed to simplify them to a & b & -c but that's not optimal. Now it recurses on some operators that may return bool when used with bool operands: &, |, ^, * (in the case of &, it's bool if either operand is; for the rest, it's bool if both are). As a result, the above now simplifies to a & b & c, which is optimal.
This commit is contained in:
parent
61565470a2
commit
3f61e6f7bf
1 changed files with 2 additions and 0 deletions
|
@ -103,6 +103,8 @@ class foldconst(object):
|
|||
nt = node['nt']
|
||||
if nt in ('<', '!', '>', '<=', '>=', '==', '||', '&&') \
|
||||
or nt == '!=' and node['ch'][0]['t'] != 'list' \
|
||||
or nt == '&' and (self.IsBool(node['ch'][0]) or self.IsBool(node['ch'][1])) \
|
||||
or nt in ('|', '^', '*') and self.IsBool(node['ch'][0]) and self.IsBool(node['ch'][1]) \
|
||||
or nt == 'CONST' and node['t'] == 'integer' and node['value'] in (0, 1):
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue