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 9ded9eaa63683bd3fcf314347bd275ad3e251695..ff20cf6ed7180fb05620e3236b94254183c67165 100644 |
--- a/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
+++ b/third_party/WebKit/Source/build/scripts/templates/fields/field.tmpl |
@@ -53,3 +53,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) -%} |
+ {{setter_expression(field)}} = other.{{getter_expression(field)}}; |
+{% endfor %} |
+{% endmacro %} |