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
conditions = [x for x in map(self.apply_condition, self.conditions) if x is not None]
conditions = (',\n' + ' '*9).join(conditions)
return dedent('''\
program:
{sig}
test(and(
{conditions}
), '{color}', '');
''').format(sig=self.signature, conditions=conditions,
color=self.color)
if len(self.conditions) > 1:
return dedent('''\
program:
{sig}
test(and(
{conditions}
), '{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):
col, action, val = condition