mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Add optimizer option 'listlength' to optimize llGetListLength.
llGetListLength(arg) was transformed to arg!=[] whenever constant folding was active. This option allows disabling that optimization.
This commit is contained in:
parent
e8852ad124
commit
f0c115f924
3 changed files with 5 additions and 2 deletions
|
@ -1001,7 +1001,7 @@ class foldconst(object):
|
|||
warning(u"Can't optimize call to %s because it would generate a tab character (you can force the optimization with the 'foldtabs' option, or disable this warning by disabling the 'warntabs' option)." % node['name'].decode('utf8'))
|
||||
return
|
||||
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value, 'SEF':True}
|
||||
elif node['name'] == 'llGetListLength':
|
||||
elif self.optlistlength and node['name'] == 'llGetListLength':
|
||||
# Convert llGetListLength(expr) to (expr != [])
|
||||
node = {'nt':'CONST', 't':'list', 'value':[]}
|
||||
parent[index] = node = {'nt':'!=', 't':'list', 'ch':[child[0], node]}
|
||||
|
|
|
@ -74,6 +74,7 @@ class optimizer(foldconst, renamer, deadcode):
|
|||
self.shrinknames = 'shrinknames' in options
|
||||
|
||||
self.constfold = 'constfold' in options
|
||||
self.optlistlength = 'listlength' in options
|
||||
self.dcr = 'dcr' in options
|
||||
|
||||
# Math that works fine except in rare corner-cases can be optimized.
|
||||
|
|
4
main.py
4
main.py
|
@ -282,6 +282,7 @@ Case insensitive.
|
|||
would keep a single copy of "longstring", while if the
|
||||
strings are added, both "alongstring" and "blongstring"
|
||||
take memory.
|
||||
ListLength + Optimize llGetListLength(arg) to arg!=[].
|
||||
|
||||
Miscellaneous options
|
||||
|
||||
|
@ -318,7 +319,7 @@ validoptions = frozenset(('extendedglobalexpr','breakcont','extendedtypecast',
|
|||
'extendedassignment','allowkeyconcat','allowmultistrings','duplabels',
|
||||
'lazylists','enableswitch','errmissingdefault','funcoverride','optimize',
|
||||
'optsigns','optfloats','constfold','dcr','shrinknames','addstrings',
|
||||
'foldtabs','warntabs','processpre','explicitcast',
|
||||
'foldtabs','warntabs','processpre','explicitcast','listlength',
|
||||
'help','lso','expr'
|
||||
# 'clear' is handled as a special case
|
||||
))
|
||||
|
@ -334,6 +335,7 @@ def main(argv):
|
|||
options = set(('extendedglobalexpr','extendedtypecast','extendedassignment',
|
||||
'allowkeyconcat','allowmultistrings','processpre','warntabs','optimize',
|
||||
'optsigns','optfloats','constfold','dcr','errmissingdefault',
|
||||
'listlength',
|
||||
))
|
||||
|
||||
assert not (options - validoptions), (u"Default options not present in"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue