mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 08:27:22 +03:00
Use a set instead of a regex to detect INITIAL_NOT_COMPUTED values
That's an easy ~1% performance enhancement!
This commit is contained in:
parent
1076b106ea
commit
572822a353
@ -20,7 +20,6 @@
|
||||
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
import cssselect2
|
||||
@ -29,6 +28,7 @@ import tinycss2
|
||||
from . import properties
|
||||
from . import computed_values
|
||||
from .descriptors import preprocess_descriptors
|
||||
from .properties import INITIAL_NOT_COMPUTED
|
||||
from .validation import (preprocess_declarations, remove_whitespace,
|
||||
split_on_comma)
|
||||
from ..compat import iteritems
|
||||
@ -40,12 +40,6 @@ from .. import CSS
|
||||
# Reject anything not in here:
|
||||
PSEUDO_ELEMENTS = (None, 'before', 'after', 'first-line', 'first-letter')
|
||||
|
||||
# A test function that returns True if the given property name has an
|
||||
# initial value that is not always the same when computed.
|
||||
RE_INITIAL_NOT_COMPUTED = re.compile(
|
||||
'^(display|column_gap|(bleed_(left|right|top|bottom))|'
|
||||
'(border_[a-z]+|outline|column_rule)_(width|color))$').match
|
||||
|
||||
|
||||
class StyleDict(dict):
|
||||
"""A dict allowing attribute access to values.
|
||||
@ -569,7 +563,7 @@ def computed_from_cascaded(element, cascaded, parent_style, pseudo_type=None,
|
||||
|
||||
if keyword == 'initial':
|
||||
value = initial
|
||||
if not RE_INITIAL_NOT_COMPUTED(name):
|
||||
if name not in INITIAL_NOT_COMPUTED:
|
||||
# The value is the same as when computed
|
||||
computed[name] = value
|
||||
elif keyword == 'inherit':
|
||||
|
@ -316,3 +316,27 @@ TABLE_WRAPPER_BOX_PROPERTIES = set('''
|
||||
vertical_align
|
||||
z_index
|
||||
'''.split())
|
||||
|
||||
|
||||
# Properties that have an initial value that is not always the same when
|
||||
# computed.
|
||||
INITIAL_NOT_COMPUTED = set('''
|
||||
display
|
||||
column_gap
|
||||
bleed_top
|
||||
bleed_left
|
||||
bleed_bottom
|
||||
bleed_right
|
||||
outline_width
|
||||
outline_color
|
||||
column_rule_width
|
||||
column_rule_color
|
||||
border_top_width
|
||||
border_left_width
|
||||
border_bottom_width
|
||||
border_right_width
|
||||
border_top_color
|
||||
border_left_color
|
||||
border_bottom_color
|
||||
border_right_color
|
||||
'''.split())
|
||||
|
Loading…
Reference in New Issue
Block a user