Index: third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
diff --git a/third_party/WebKit/Source/build/scripts/make_computed_style_base.py b/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
index f9011169215a146ce4ea09ee5908ec8183d57339..339da70244abcf9d13a084bcd8a8d58f62c668b5 100755 |
--- a/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
+++ b/third_party/WebKit/Source/build/scripts/make_computed_style_base.py |
@@ -62,6 +62,11 @@ class Field(object): |
]) |
def __init__(self, field_role, **kwargs): |
+ # TODO(shend): get rid of this kwargs thing by creating separate classes |
+ # for each field template and taking in normal arguments, then remove the |
+ # line below |
+ # pylint: disable=no-member |
meade_UTC10
2017/02/17 06:56:05
Is this a new lint that got enabled? o.O
shend
2017/02/19 23:10:17
Urgh, the comment doesn't explain anything, I upda
|
+ |
# Values common to all fields |
# Set attributes from the keyword arguments |
for attrib in Field.REQUIRED_ATTRIBUTES: |
@@ -84,6 +89,9 @@ class Field(object): |
# Inherited flag-only fields |
pass |
+ # Only pack the field if the field size is not None |
meade_UTC10
2017/02/17 06:56:05
nit: Does this mean when the field is used as inpu
shend
2017/02/19 23:10:17
Yeah "packed" is ambiguous. I changed it to 'is_bi
|
+ self.is_packed = self.size is not None |
+ |
assert len(kwargs) == 0, 'Unexpected arguments provided to Field: ' + str(kwargs) |
@@ -131,9 +139,8 @@ def _create_property_field(property_): |
# From the Blink style guide: Other data members should be prefixed by "m_". [names-data-members] |
field_name = 'm_' + property_name_lower |
- bits_needed = math.log(len(property_['keywords']), 2) # TODO: implement for non-enums |
- # Separate the type path from the type name, if specified. |
+ # Override the type_name if field_type_path is specified |
if property_['field_type_path']: |
type_name = property_['field_type_path'].split('/')[-1] |
else: |
@@ -146,10 +153,15 @@ def _create_property_field(property_): |
if type_name == property_name: |
getter_method_name = 'get' + property_name |
- assert property_['initial_keyword'] is not None, \ |
- ('MakeComputedStyleBase requires an initial keyword for keyword fields, none specified ' |
- 'for property ' + property_['name']) |
- default_value = type_name + '::k' + camel_case(property_['initial_keyword']) |
+ if property_['field_template'] == 'keyword': |
+ assert property_['default_value'] is not None, \ |
+ ('MakeComputedStyleBase requires an initial keyword for keyword fields, none specified ' |
+ 'for property ' + property_['name']) |
+ bits_needed = int(math.ceil(math.log(len(property_['keywords']), 2))) |
+ default_value = type_name + '::k' + camel_case(property_['default_value']) |
+ else: |
+ bits_needed = None |
+ default_value = property_['default_value'] |
return Field( |
'property', |
@@ -159,7 +171,7 @@ def _create_property_field(property_): |
independent=property_['independent'], |
type_name=type_name, |
field_template=property_['field_template'], |
- size=int(math.ceil(bits_needed)), |
+ size=bits_needed, |
default_value=default_value, |
getter_method_name=getter_method_name, |
setter_method_name='set' + property_name, |
@@ -286,12 +298,16 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
# Create all the fields |
all_fields = _create_fields(self._properties.values()) |
- # Group fields into buckets |
- field_buckets = _pack_fields(all_fields) |
+ # Separate the normal data members from the bit fields |
+ packed_fields = [field for field in all_fields if field.is_packed] |
+ unpacked_fields = [field for field in all_fields if not field.is_packed] |
+ |
+ # Pack fields into buckets |
+ field_buckets = _pack_fields(packed_fields) |
# The expected size of ComputedStyleBase is equivalent to as many words |
# as the total number of buckets. |
- self._expected_total_field_bytes = len(field_buckets) |
+ self._expected_bitfield_bytes = len(field_buckets) |
# The most optimal size of ComputedStyleBase is the total sum of all the |
# field sizes, rounded up to the nearest word. If this produces the |
@@ -303,14 +319,16 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
# We should be able to bring extra_padding_bytes back to 0 from time to |
# time. |
extra_padding_bytes = 0 |
- optimal_total_field_bytes = int(math.ceil(sum(f.size for f in all_fields) / 32.0)) |
- real_total_field_bytes = optimal_total_field_bytes + extra_padding_bytes |
- assert self._expected_total_field_bytes == real_total_field_bytes, \ |
+ optimal_bitfield_bytes = int(math.ceil(sum(f.size for f in packed_fields) / 32.0)) |
+ real_bitfield_bytes = optimal_bitfield_bytes + extra_padding_bytes |
+ assert self._expected_bitfield_bytes == real_bitfield_bytes, \ |
('The field packing algorithm produced %s bytes, optimal is %s bytes' % |
- (self._expected_total_field_bytes, real_total_field_bytes)) |
+ (self._expected_bitfield_bytes, real_bitfield_bytes)) |
+ |
+ # Unpacked fields go first, then the packed fields. |
+ self._fields = list(unpacked_fields) |
# Order the fields so fields in each bucket are adjacent. |
- self._fields = [] |
for bucket in field_buckets: |
for field in bucket: |
self._fields.append(field) |
@@ -323,7 +341,6 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
'enums': self._generated_enums, |
'include_paths': _get_include_paths(self._properties.values()), |
'fields': self._fields, |
- 'expected_total_field_bytes': self._expected_total_field_bytes, |
} |
@template_expander.use_jinja('ComputedStyleBase.cpp.tmpl') |
@@ -332,7 +349,7 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
'properties': self._properties, |
'enums': self._generated_enums, |
'fields': self._fields, |
- 'expected_total_field_bytes': self._expected_total_field_bytes, |
+ 'expected_bitfield_bytes': self._expected_bitfield_bytes, |
} |
@template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
@@ -341,7 +358,6 @@ class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |
'properties': self._properties, |
'enums': self._generated_enums, |
'fields': self._fields, |
- 'expected_total_field_bytes': self._expected_total_field_bytes, |
} |
if __name__ == '__main__': |