Index: third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
diff --git a/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl b/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
index e4cc5ed447e9bd66ee8d12bb75b223e0146648ea..0ac11a96b44b78ab5ce3caea9003d10f34f08cac 100644 |
--- a/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
+++ b/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
@@ -45,3 +45,36 @@ unsigned {{field.name}} : {{field.size}}; // {{field.type_name}} |
{{field.type_name}} {{field.name}}; |
{%- endif %} |
{% endmacro %} |
+ |
+{# Given a group and a list of fields to compare, this generates a set of |
+ equality comparisons on those fields. The generated comparisons take |
+ advantage of group sharing. #} |
+{% macro fieldwise_compare(group, fields_to_compare) %} |
+{% for subgroup in group.subgroups %} |
+ {# If every field in this subgroup is to be compared, we can compare the |
+ group pointer instead. #} |
+ {% if subgroup.all_fields|reject("in", fields_to_compare)|list|length == 0 -%} |
+ {{subgroup.member_name}} == o.{{subgroup.member_name}} && |
+ {# Otherwise, we would have to recursively generate comparison operations |
+ on fields in the subgroup. #} |
+ {% elif subgroup.fields|select("in", fields_to_compare)|list|length > 0 -%} |
+ {{fieldwise_compare(subgroup, fields_to_compare)}} |
+ {% endif %} |
+{% endfor %} |
+{% for field in group.fields|select("in", fields_to_compare) -%} |
+ {{getter_expression(field)}} == o.{{getter_expression(field)}} && |
+{% endfor %} |
+{% endmacro %} |
+ |
+{% macro fieldwise_copy(group, fields_to_copy) %} |
+{% for subgroup in group.subgroups %} |
+ {% if subgroup.all_fields|reject("in", fields_to_copy)|list|length == 0 -%} |
+ {{subgroup.member_name}} = other.{{subgroup.member_name}}; |
+ {% elif subgroup.fields|select("in", fields_to_copy)|list|length > 0 -%} |
+ {{fieldwise_copy(subgroup, fields_to_copy)}} |
+ {% endif %} |
+{% endfor %} |
+{% for field in group.fields|select("in", fields_to_copy) -%} |
+ {{getter_expression(field)}} = other.{{getter_expression(field)}}; |
nainar
2017/04/19 04:46:39
setter_expression(field)
shend
2017/04/20 00:17:33
Done.
|
+{% endfor %} |
+{% endmacro %} |