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,6 +62,7 @@ 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)
if len(self.conditions) > 1:
return dedent('''\ return dedent('''\
program: program:
{sig} {sig}
@ -70,6 +71,13 @@ class Rule(object): # {{{
), '{color}', ''); ), '{color}', '');
''').format(sig=self.signature, conditions=conditions, ''').format(sig=self.signature, conditions=conditions,
color=self.color) 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