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

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: 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..56398570ec707adfc991b69f21f474d3f49a146e 100644
--- a/Source/build/scripts/templates/ElementFactory.cpp.tmpl
+++ b/Source/build/scripts/templates/ElementFactory.cpp.tmpl
@@ -58,18 +58,21 @@ static PassRefPtr<{{namespace}}Element> {{tag|symbol}}Constructor(
}
{%- endfor %}
-static void addTag(const QualifiedName& tag, ConstructorFunction func)
-{
- g_constructors->set(tag.localName(), func);
-}
-
static void createFunctionMap()
{
ASSERT(!g_constructors);
g_constructors = new FunctionMap;
+ struct CreateFunctionMapData {
+ const QualifiedName& tag;
+ ConstructorFunction func;
+ };
+ const CreateFunctionMapData data[] = {
adamk 2014/02/18 18:28:41 Not sure if it matters (since this is only called
Daniel Bratell 2014/02/19 13:41:05 It's a tricky question. For a compile time constan
{%- 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 < sizeof(data) / sizeof(*data); i++)
adamk 2014/02/18 18:28:41 Nit: you can use WTF_ARRAY_LENGTH() (from wtf/StdL
Daniel Bratell 2014/02/19 13:41:05 Thanks!
+ g_constructors->set(data[i].tag.localName(), data[i].func);
}
PassRefPtr<{{namespace}}Element> {{namespace}}ElementFactory::create{{namespace}}Element(
« 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