mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improve performance of rules templates by not calling the "and" function if there is only one condition.
This commit is contained in:
parent
545ce0b6ce
commit
5187d5dc02
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user