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

Unified Diff: third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl

Issue 2755323002: [Bindings] Emit less code per member in generated dictionary ToV8. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/tests/results/core/V8TestDictionary.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
diff --git a/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
index bf6096e026e0b8dfe7d1f006a56f0b80a2891bb4..9e71c4872edbf64afc3e6003796ee97b835435b9 100644
--- a/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
+++ b/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
@@ -100,25 +100,35 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
{% endif %}
{% for member in members %}
+ v8::Local<v8::Value> {{member.name}}Value;
+ bool {{member.name}}HasValueOrDefault = false;
if (impl.{{member.has_method_name}}()) {
{% if member.is_object %}
DCHECK(impl.{{member.getter_name}}().isObject());
{% endif %}
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}})))
- return false;
+ {{member.name}}Value = {{member.cpp_value_to_v8_value}};
+ {{member.name}}HasValueOrDefault = true;
{% if member.v8_default_value %}
} else {
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.v8_default_value}})))
- return false;
+ {{member.name}}Value = {{member.v8_default_value}};
+ {{member.name}}HasValueOrDefault = true;
{% elif member.is_nullable %}
} else {
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), v8::Null(isolate))))
- return false;
+ {{member.name}}Value = v8::Null(isolate);
+ {{member.name}}HasValueOrDefault = true;
{% elif member.is_required %}
} else {
NOTREACHED();
{% endif %}
}
+ {# The HasValueOrDefault variable will be optimized out.
+ If there is a default value, the compiler will notice that all branches set it to true.
+ If there is not, then the compiler will inline this call into the only branch that sets it to true.
+ Either way, the code is efficient and the variable is completely elided. #}
+ if ({{member.name}}HasValueOrDefault &&
+ !v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.name}}Value))) {
+ return false;
+ }
{% endfor %}
return true;
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/tests/results/core/V8TestDictionary.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698