From c2437b33e73d1f066cfcadd1dff631090ededdde Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 17 Aug 2014 16:31:46 +0200 Subject: [PATCH] Optimize [] + nonlist as (list)nonlist. And minor comment changes. --- lslopt/lslfoldconst.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 617fe58..2b0b86e 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -245,12 +245,9 @@ class foldconst(object): # Tough one. Remove neutral elements for the diverse types, # and more. if optype == 'list' and not (ltype == rtype == 'list'): - # Nothing to do with list + nonlist or nonlist + list. - # FIXME: Not true. (list)"string" is a 5 byte saving vs. - # [] + "string". Activating explicitcast forces the - # conversion [] + (list)"string" -> (list)"string" which - # is what we want here, but it is a loss for other types. - # Further analysis needed. + if lnt == 'CONST' and not lval['value']: + # [] + nonlist -> (list)nonlist + parent[index] = self.Cast(rval, optype) return if optype in ('vector', 'rotation'): @@ -264,16 +261,16 @@ class foldconst(object): return # Can't be key, as no combo of addition operands returns key - # All these types evaluate as boolean False when they are + # All these types evaluate to boolean False when they are # the neutral addition element. if optype in ('string', 'float', 'list'): if lnt == 'CONST' and not lval['value']: - # 0 + expr -> expr + # 0. + expr -> expr # "" + expr -> expr # [] + expr -> expr parent[index] = self.Cast(rval, optype) elif rnt == 'CONST' and not rval['value']: - # expr + 0 -> expr + # expr + 0. -> expr # expr + "" -> expr # expr + [] -> expr parent[index] = self.Cast(lval, optype)