Chromium Code Reviews| 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 958cc0f1828eca7c47914c398f4de458753f31c1..07ca9824683f69434a335ae6dca01a3945befc79 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,59 +17,89 @@ 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}}]; |
|
Jens Widell
2014/09/25 17:16:16
Could you declare an
const {{namespace}}Qualifi
Daniel Bratell
2014/09/25 17:48:42
I've tried it but it generates warnings like this:
|
| {% endfor %} |
| 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 %} |
| // 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 %} |
| 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(); |
| } |
| 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}} |