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

Unified Diff: Source/build/scripts/templates/ElementFactory.cpp.tmpl

Issue 170793003: Use data driven code when registering constructors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Another attempt at fixing gcc compilation. Created 6 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/templates/ElementFactory.cpp.tmpl
diff --git a/Source/build/scripts/templates/ElementFactory.cpp.tmpl b/Source/build/scripts/templates/ElementFactory.cpp.tmpl
index 1eca356b5b8cecf14501064c6f9d6725ab44b4a8..1ac6129aa2be1dc2a1fc952156d1f36fd49bec50 100644
--- a/Source/build/scripts/templates/ElementFactory.cpp.tmpl
+++ b/Source/build/scripts/templates/ElementFactory.cpp.tmpl
@@ -58,18 +58,22 @@ static PassRefPtr<{{namespace}}Element> {{tag|symbol}}Constructor(
}
{%- endfor %}
-static void addTag(const QualifiedName& tag, ConstructorFunction func)
-{
- g_constructors->set(tag.localName(), func);
-}
+struct Create{{namespace}}FunctionMapData {
+ const QualifiedName& tag;
+ ConstructorFunction func;
+};
-static void createFunctionMap()
+static void create{{namespace}}FunctionMap()
{
ASSERT(!g_constructors);
g_constructors = new FunctionMap;
+ static const Create{{namespace}}FunctionMapData data[] = {
{%- for tag in tags|sort if not tag.noConstructor %}
- addTag({{tag|symbol}}Tag, {{tag|symbol}}Constructor);
+ { {{tag|symbol}}Tag, {{tag|symbol}}Constructor },
{%- endfor %}
+ };
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(data); i++)
+ g_constructors->set(data[i].tag.localName(), data[i].func);
}
PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(
@@ -81,7 +85,7 @@ PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}
bool createdByParser)
{
if (!g_constructors)
- createFunctionMap();
+ create{{namespace}}FunctionMap();
if (ConstructorFunction function = g_constructors->get(localName))
return function(document, {%- if namespace == 'HTML' %}formElement,{% endif %} createdByParser);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698