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
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user