Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1408)

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl

Issue 2339413004: Allow Mojo structs as map keys (Closed)
Patch Set: Fix hash unit test on Windows Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl
index e905904174d920db89fbd7ef087b7fb70b890929..80527a21ce78a514b61a262112585a7914f3d566 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_union_class_definition.tmpl
@@ -65,3 +65,23 @@ void {{union.name}}::DestroyActive() {
{%- endfor %}
}
}
+
+{%- if union|is_hashable %}
+size_t {{union.name}}::Hash(size_t seed) const {
+ seed = mojo::internal::HashCombine(seed, static_cast<uint32_t>(tag_));
+ switch (tag_) {
+{% for field in union.fields %}
+ case Tag::{{field.name|upper}}:
+{%- if for_blink %}
+ return mojo::internal::WTFHash(seed, data_.{{field.name}});
+{%- else %}
+ return mojo::internal::Hash(seed, data_.{{field.name}});
+{%- endif %}
+{%- endfor %}
+ default:
+ NOTREACHED();
+ return seed;
+ }
+}
+
+{%- endif %}

Powered by Google App Engine
This is Rietveld 408576698