Chromium Code Reviews| 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 b52ab45c015cddf0ee10ad7f4a8b266460fa3d80..bff95db7c6d4593b300c3d775aeab00952cf1f5b 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 |
| @@ -17,6 +17,19 @@ from name_utilities import ( |
| from collections import defaultdict, OrderedDict |
| from itertools import chain |
| +# We want to sort fields by their alignment sizes. Specifying the exact alignment requirements |
|
Bugs Nash
2017/04/28 00:16:51
Add to the comment where the types hard coded here
shend
2017/04/28 01:00:31
done
|
| +# for each type is impossible because it's platform specific. Instead, we will define an ordering |
| +# on types, from largest alignment size to smallest. This heuristic should work most of the time. |
| +ALIGNMENT_ORDER = [ |
| + 'FillLayer', 'BorderData', # Aligns like a void * |
| + 'double', |
| + 'LengthBox', 'Length', 'float', |
| + 'Color', 'unsigned', 'int', |
| + 'short', |
| + 'char', |
| + 'bool' |
| +] |
| + |
| # TODO(shend): Improve documentation and add docstrings. |
| @@ -272,14 +285,7 @@ def _create_fields(properties): |
| return fields |
| -def _reorder_fields(fields): |
| - """ |
| - Returns a list of fields ordered to minimise padding. |
| - """ |
| - # Separate out bit fields from non bit fields |
| - bit_fields = [field for field in fields if field.is_bit_field] |
| - non_bit_fields = [field for field in fields if not field.is_bit_field] |
| - |
| +def _reorder_bit_fields(bit_fields): |
| # Since fields cannot cross word boundaries, in order to minimize |
| # padding, group fields into buckets so that as many buckets as possible |
| # are exactly 32 bits. Although this greedy approach may not always |
| @@ -305,8 +311,28 @@ def _reorder_fields(fields): |
| if not added_to_bucket: |
| field_buckets.append([field]) |
| + return _flatten_list(field_buckets) |
| + |
| + |
| +def _reorder_non_bit_fields(non_bit_fields): |
| + # A general rule of thumb is to sort members by their alignment requirement |
| + # (from biggest aligned to smallest). If we don't know its alignment, we |
| + # assume the worst and put it at the front. |
| + known_alignment = [field for field in non_bit_fields if field.type_name in ALIGNMENT_ORDER] |
|
Bugs Nash
2017/04/28 00:16:51
nit: swap these lines so that unknown_alignment co
shend
2017/04/28 01:00:30
done
|
| + unknown_alignment = [field for field in non_bit_fields if field.type_name not in ALIGNMENT_ORDER] |
| + return unknown_alignment + list(sorted(known_alignment, key=lambda f: ALIGNMENT_ORDER.index(f.type_name))) |
| + |
| + |
| +def _reorder_fields(fields): |
| + """ |
| + Returns a list of fields ordered to minimise padding. |
| + """ |
| + # Separate out bit fields from non bit fields |
| + bit_fields = [field for field in fields if field.is_bit_field] |
| + non_bit_fields = [field for field in fields if not field.is_bit_field] |
| + |
| # Non bit fields go first, then the bit fields. |
| - return list(non_bit_fields) + _flatten_list(field_buckets) |
| + return _reorder_non_bit_fields(non_bit_fields) + _reorder_bit_fields(bit_fields) |
| class ComputedStyleBaseWriter(make_style_builder.StyleBuilderWriter): |