Skip to content

Commit 498d3e1

Browse files
committedSep 30, 2022
Optimize __missing__ functions
1 parent 028ec78 commit 498d3e1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
 

‎weasyprint/css/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -626,18 +626,18 @@ def copy(self):
626626
return copy
627627

628628
def __missing__(self, key):
629-
if key in INHERITED or key.startswith('__'):
630-
self[key] = self.parent_style[key]
629+
if key in INHERITED or key[:2] == '__':
630+
value = self[key] = self.parent_style[key]
631631
elif key == 'page':
632632
# page is not inherited but taken from the ancestor if 'auto'
633-
self[key] = self.parent_style[key]
634-
elif key.startswith('text_decoration_'):
635-
self[key] = text_decoration(
633+
value = self[key] = self.parent_style[key]
634+
elif key[:16] == 'text_decoration_':
635+
value = self[key] = text_decoration(
636636
key, INITIAL_VALUES[key], self.parent_style[key],
637637
cascaded=False)
638638
else:
639-
self[key] = INITIAL_VALUES[key]
640-
return self[key]
639+
value = self[key] = INITIAL_VALUES[key]
640+
return value
641641

642642

643643
class ComputedStyle(dict):
@@ -676,7 +676,7 @@ def __missing__(self, key):
676676
if key in self.cascaded:
677677
value = keyword = self.cascaded[key][0]
678678
else:
679-
if key in INHERITED or key.startswith('__'):
679+
if key in INHERITED or key[:2] == '__':
680680
keyword = 'inherit'
681681
else:
682682
keyword = 'initial'
@@ -686,15 +686,15 @@ def __missing__(self, key):
686686
keyword = 'initial'
687687

688688
if keyword == 'initial':
689-
value = None if key.startswith('__') else INITIAL_VALUES[key]
689+
value = None if key[:2] == '__' else INITIAL_VALUES[key]
690690
if key not in INITIAL_NOT_COMPUTED:
691691
# The value is the same as when computed
692692
self[key] = value
693693
elif keyword == 'inherit':
694694
# Values in parent_style are already computed.
695695
self[key] = value = self.parent_style[key]
696696

697-
if key.startswith('text_decoration_') and self.parent_style:
697+
if key[:16] == 'text_decoration_' and self.parent_style:
698698
value = text_decoration(
699699
key, value, self.parent_style[key], key in self.cascaded)
700700
if key in self:

0 commit comments

Comments
 (0)
Please sign in to comment.