Skip to content

Commit

Permalink
Optimize __missing__ functions
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Sep 30, 2022
1 parent 028ec78 commit 498d3e1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions weasyprint/css/__init__.py
Expand Up @@ -626,18 +626,18 @@ def copy(self):
return copy

def __missing__(self, key):
if key in INHERITED or key.startswith('__'):
self[key] = self.parent_style[key]
if key in INHERITED or key[:2] == '__':
value = self[key] = self.parent_style[key]
elif key == 'page':
# page is not inherited but taken from the ancestor if 'auto'
self[key] = self.parent_style[key]
elif key.startswith('text_decoration_'):
self[key] = text_decoration(
value = self[key] = self.parent_style[key]
elif key[:16] == 'text_decoration_':
value = self[key] = text_decoration(
key, INITIAL_VALUES[key], self.parent_style[key],
cascaded=False)
else:
self[key] = INITIAL_VALUES[key]
return self[key]
value = self[key] = INITIAL_VALUES[key]
return value


class ComputedStyle(dict):
Expand Down Expand Up @@ -676,7 +676,7 @@ def __missing__(self, key):
if key in self.cascaded:
value = keyword = self.cascaded[key][0]
else:
if key in INHERITED or key.startswith('__'):
if key in INHERITED or key[:2] == '__':
keyword = 'inherit'
else:
keyword = 'initial'
Expand All @@ -686,15 +686,15 @@ def __missing__(self, key):
keyword = 'initial'

if keyword == 'initial':
value = None if key.startswith('__') else INITIAL_VALUES[key]
value = None if key[:2] == '__' else INITIAL_VALUES[key]
if key not in INITIAL_NOT_COMPUTED:
# The value is the same as when computed
self[key] = value
elif keyword == 'inherit':
# Values in parent_style are already computed.
self[key] = value = self.parent_style[key]

if key.startswith('text_decoration_') and self.parent_style:
if key[:16] == 'text_decoration_' and self.parent_style:
value = text_decoration(
key, value, self.parent_style[key], key in self.cascaded)
if key in self:
Expand Down

0 comments on commit 498d3e1

Please sign in to comment.