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:
Sei Lisa 2017-01-25 19:22:36 +01:00
parent e8852ad124
commit f0c115f924
3 changed files with 5 additions and 2 deletions

View file

@ -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')) 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 return
parent[index] = {'nt':'CONST', 't':node['t'], 'value':value, 'SEF':True} 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 != []) # Convert llGetListLength(expr) to (expr != [])
node = {'nt':'CONST', 't':'list', 'value':[]} node = {'nt':'CONST', 't':'list', 'value':[]}
parent[index] = node = {'nt':'!=', 't':'list', 'ch':[child[0], node]} parent[index] = node = {'nt':'!=', 't':'list', 'ch':[child[0], node]}

View file

@ -74,6 +74,7 @@ class optimizer(foldconst, renamer, deadcode):
self.shrinknames = 'shrinknames' in options self.shrinknames = 'shrinknames' in options
self.constfold = 'constfold' in options self.constfold = 'constfold' in options
self.optlistlength = 'listlength' in options
self.dcr = 'dcr' in options self.dcr = 'dcr' in options
# Math that works fine except in rare corner-cases can be optimized. # Math that works fine except in rare corner-cases can be optimized.

View file

@ -282,6 +282,7 @@ Case insensitive.
would keep a single copy of "longstring", while if the would keep a single copy of "longstring", while if the
strings are added, both "alongstring" and "blongstring" strings are added, both "alongstring" and "blongstring"
take memory. take memory.
ListLength + Optimize llGetListLength(arg) to arg!=[].
Miscellaneous options Miscellaneous options
@ -318,7 +319,7 @@ validoptions = frozenset(('extendedglobalexpr','breakcont','extendedtypecast',
'extendedassignment','allowkeyconcat','allowmultistrings','duplabels', 'extendedassignment','allowkeyconcat','allowmultistrings','duplabels',
'lazylists','enableswitch','errmissingdefault','funcoverride','optimize', 'lazylists','enableswitch','errmissingdefault','funcoverride','optimize',
'optsigns','optfloats','constfold','dcr','shrinknames','addstrings', 'optsigns','optfloats','constfold','dcr','shrinknames','addstrings',
'foldtabs','warntabs','processpre','explicitcast', 'foldtabs','warntabs','processpre','explicitcast','listlength',
'help','lso','expr' 'help','lso','expr'
# 'clear' is handled as a special case # 'clear' is handled as a special case
)) ))
@ -334,6 +335,7 @@ def main(argv):
options = set(('extendedglobalexpr','extendedtypecast','extendedassignment', options = set(('extendedglobalexpr','extendedtypecast','extendedassignment',
'allowkeyconcat','allowmultistrings','processpre','warntabs','optimize', 'allowkeyconcat','allowmultistrings','processpre','warntabs','optimize',
'optsigns','optfloats','constfold','dcr','errmissingdefault', 'optsigns','optfloats','constfold','dcr','errmissingdefault',
'listlength',
)) ))
assert not (options - validoptions), (u"Default options not present in" assert not (options - validoptions), (u"Default options not present in"