Improve performance of rules templates by not calling the "and" function if there is only one condition.

This commit is contained in:
Charles Haley 2020-04-18 18:33:09 +01:00
parent 545ce0b6ce
commit 5187d5dc02

View File

@ -62,14 +62,22 @@ class Rule(object): # {{{
return None return None
conditions = [x for x in map(self.apply_condition, self.conditions) if x is not None] conditions = [x for x in map(self.apply_condition, self.conditions) if x is not None]
conditions = (',\n' + ' '*9).join(conditions) conditions = (',\n' + ' '*9).join(conditions)
return dedent('''\ if len(self.conditions) > 1:
program: return dedent('''\
{sig} program:
test(and( {sig}
{conditions} test(and(
), '{color}', ''); {conditions}
''').format(sig=self.signature, conditions=conditions, ), '{color}', '');
color=self.color) ''').format(sig=self.signature, conditions=conditions,
color=self.color)
else:
return dedent('''\
program:
{sig}
test({conditions}, '{color}', '');
''').format(sig=self.signature, conditions=conditions,
color=self.color)
def apply_condition(self, condition): def apply_condition(self, condition):
col, action, val = condition col, action, val = condition