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

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

Issue 604743003: MakeNames: Generate global constants in a loop rather than in sequence. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: MakeNames: Rebased to newer origin/master Created 6 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
« no previous file with comments | « Source/build/scripts/templates/MakeNames.cpp.tmpl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/build/scripts/templates/MakeQualifiedNames.cpp.tmpl
diff --git a/Source/build/scripts/templates/MakeQualifiedNames.cpp.tmpl b/Source/build/scripts/templates/MakeQualifiedNames.cpp.tmpl
index f5eb9838181ca5790dcdaa3a517210a1837f80a2..1e36db421d57f8f9a305bd8e2ed7b01eae6b4e63 100644
--- a/Source/build/scripts/templates/MakeQualifiedNames.cpp.tmpl
+++ b/Source/build/scripts/templates/MakeQualifiedNames.cpp.tmpl
@@ -6,6 +6,7 @@
#include "{{namespace}}Names.h"
#include "wtf/StaticConstructors.h"
+#include "wtf/StdLibExtras.h"
namespace blink {
namespace {{namespace}}Names {
@@ -16,8 +17,10 @@ DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI)
{% if tags %}
// Tags
-{% for tag in tags|sort %}
-DEFINE_GLOBAL({{namespace}}QualifiedName, {{tag|symbol}}Tag)
+
+void* {{suffix}}TagStorage[{{namespace}}TagsCount * ((sizeof({{namespace}}QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];
+{% for tag in tags|sort(attribute='name', case_sensitive=True) %}
+const {{namespace}}QualifiedName& {{tag|symbol}}Tag = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage)[{{loop.index0}}];
{% endfor %}
@@ -25,26 +28,27 @@ DEFINE_GLOBAL({{namespace}}QualifiedName, {{tag|symbol}}Tag)
PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags()
{
OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {{namespace}}QualifiedName*[{{namespace}}TagsCount]);
- {% for tag in tags|sort %}
- tags[{{loop.index0}}] = reinterpret_cast<const {{namespace}}QualifiedName*>(&{{tag|symbol}}Tag);
- {% endfor %}
+ for (size_t i = 0; i < {{namespace}}TagsCount; i++)
+ tags[i] = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + i;
return tags.release();
}
{% endif %}
{% endif %}
// Attributes
-{% for attr in attrs|sort %}
-DEFINE_GLOBAL(QualifiedName, {{attr|symbol}}Attr)
+
+void* {{suffix}}AttrStorage[{{namespace}}AttrsCount * ((sizeof(QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];
+
+{% for attr in attrs|sort(attribute='name', case_sensitive=True) %}
+const QualifiedName& {{attr|symbol}}Attr = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage)[{{loop.index0}}];
{% endfor %}
{% if namespace != 'HTML' %}
PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs()
{
OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName*[{{namespace}}AttrsCount]);
- {% for attr in attrs|sort %}
- attrs[{{loop.index0}}] = reinterpret_cast<const blink::QualifiedName*>(&{{attr|symbol}}Attr);
- {% endfor %}
+ for (size_t i = 0; i < {{namespace}}AttrsCount; i++)
+ attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i;
return attrs.release();
}
{% endif %}
@@ -52,28 +56,55 @@ PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs()
void init()
{
+ struct NameEntry {
+ const char* name;
+ unsigned hash;
+ unsigned char length;
+ unsigned char isTag;
+ unsigned char isAttr;
+ };
+
// Use placement new to initialize the globals.
AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::ConstructFromLiteral);
// Namespace
new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_prefix}}NS);
- {% for name, tag_list in (tags + attrs)|groupby('name')|sort %}
- StringImpl* {{tag_list[0]|symbol}}Impl = StringImpl::createStatic("{{name}}", {{name|length}}, {{name|hash}});
- {% endfor %}
-
- // Tags
- {% for tag in tags|sort %}
- QualifiedName::createStatic((void*)&{{tag|symbol}}Tag, {{tag|symbol}}Impl, {{namespace_prefix}}NS);
+ {% set tagnames = tags|map(attribute='name')|list() %}
+ {% set attrnames = attrs|map(attribute='name')|list() %}
+ static const NameEntry kNames[] = {
+ {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, case_sensitive=True) %}
+ { "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)|int }}, {{ (name in attrnames)|int }} },
{% endfor %}
+ };
- // Attrs
- {% for attr in attrs|sort %}
- {% if use_namespace_for_attrs %}
- QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl, {{namespace_prefix}}NS);
- {% else %}
- QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl);
+ {% if tags %}
+ size_t tag_i = 0;
{% endif %}
- {% endfor %}
+ size_t attr_i = 0;
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
+ StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames[i].length, kNames[i].hash);
+ {% if tags %}
+ if (kNames[i].isTag) {
+ void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + tag_i;
+ QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
+ tag_i++;
+ }
+
+ if (!kNames[i].isAttr)
+ continue;
+ {% endif %}
+ void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i;
+ {% if use_namespace_for_attrs %}
+ QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
+ {% else %}
+ QualifiedName::createStatic(address, stringImpl);
+ {% endif %}
+ attr_i++;
+ }
+ {% if tags %}
+ ASSERT(tag_i == {{namespace}}TagsCount);
+ {% endif %}
+ ASSERT(attr_i == {{namespace}}AttrsCount);
}
} // {{namespace}}
« no previous file with comments | « Source/build/scripts/templates/MakeNames.cpp.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698