OLD | NEW |
1 {% from "macros.tmpl" import license %} | 1 {% from "macros.tmpl" import license %} |
2 {{ license() }} | 2 {{ license() }} |
3 | 3 |
4 #include "config.h" | 4 #include "config.h" |
5 | 5 |
6 #include "{{namespace}}Names.h" | 6 #include "{{namespace}}Names.h" |
7 | 7 |
8 #include "wtf/StaticConstructors.h" | 8 #include "wtf/StaticConstructors.h" |
| 9 #include "wtf/StdLibExtras.h" |
9 | 10 |
10 namespace blink { | 11 namespace blink { |
11 namespace {{namespace}}Names { | 12 namespace {{namespace}}Names { |
12 | 13 |
13 using namespace blink; | 14 using namespace blink; |
14 | 15 |
15 DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI) | 16 DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI) |
16 | 17 |
17 {% if tags %} | 18 {% if tags %} |
18 // Tags | 19 // Tags |
19 {% for tag in tags|sort %} | 20 |
20 DEFINE_GLOBAL({{namespace}}QualifiedName, {{tag|symbol}}Tag) | 21 void* {{suffix}}TagStorage[{{namespace}}TagsCount * ((sizeof({{namespace}}Qualif
iedName) + sizeof(void *) - 1) / sizeof(void *))]; |
| 22 {% for tag in tags|sort(attribute='name', case_sensitive=True) %} |
| 23 const {{namespace}}QualifiedName& {{tag|symbol}}Tag = reinterpret_cast<{{namespa
ce}}QualifiedName*>(&{{suffix}}TagStorage)[{{loop.index0}}]; |
21 {% endfor %} | 24 {% endfor %} |
22 | 25 |
23 | 26 |
24 {% if namespace == 'SVG' %} | 27 {% if namespace == 'SVG' %} |
25 PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags() | 28 PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags() |
26 { | 29 { |
27 OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {
{namespace}}QualifiedName*[{{namespace}}TagsCount]); | 30 OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {
{namespace}}QualifiedName*[{{namespace}}TagsCount]); |
28 {% for tag in tags|sort %} | 31 for (size_t i = 0; i < {{namespace}}TagsCount; i++) |
29 tags[{{loop.index0}}] = reinterpret_cast<const {{namespace}}QualifiedName*>(
&{{tag|symbol}}Tag); | 32 tags[i] = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagSt
orage) + i; |
30 {% endfor %} | |
31 return tags.release(); | 33 return tags.release(); |
32 } | 34 } |
33 {% endif %} | 35 {% endif %} |
34 | 36 |
35 {% endif %} | 37 {% endif %} |
36 // Attributes | 38 // Attributes |
37 {% for attr in attrs|sort %} | 39 |
38 DEFINE_GLOBAL(QualifiedName, {{attr|symbol}}Attr) | 40 void* {{suffix}}AttrStorage[{{namespace}}AttrsCount * ((sizeof(QualifiedName) +
sizeof(void *) - 1) / sizeof(void *))]; |
| 41 |
| 42 {% for attr in attrs|sort(attribute='name', case_sensitive=True) %} |
| 43 const QualifiedName& {{attr|symbol}}Attr = reinterpret_cast<QualifiedName*>(&{{s
uffix}}AttrStorage)[{{loop.index0}}]; |
39 {% endfor %} | 44 {% endfor %} |
40 | 45 |
41 {% if namespace != 'HTML' %} | 46 {% if namespace != 'HTML' %} |
42 PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs() | 47 PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs() |
43 { | 48 { |
44 OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName
*[{{namespace}}AttrsCount]); | 49 OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName
*[{{namespace}}AttrsCount]); |
45 {% for attr in attrs|sort %} | 50 for (size_t i = 0; i < {{namespace}}AttrsCount; i++) |
46 attrs[{{loop.index0}}] = reinterpret_cast<const blink::QualifiedName*>(&{{at
tr|symbol}}Attr); | 51 attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i; |
47 {% endfor %} | |
48 return attrs.release(); | 52 return attrs.release(); |
49 } | 53 } |
50 {% endif %} | 54 {% endif %} |
51 | 55 |
52 | 56 |
53 void init() | 57 void init() |
54 { | 58 { |
| 59 struct NameEntry { |
| 60 const char* name; |
| 61 unsigned hash; |
| 62 unsigned char length; |
| 63 unsigned char isTag; |
| 64 unsigned char isAttr; |
| 65 }; |
| 66 |
55 // Use placement new to initialize the globals. | 67 // Use placement new to initialize the globals. |
56 AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::Const
ructFromLiteral); | 68 AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::Const
ructFromLiteral); |
57 | 69 |
58 // Namespace | 70 // Namespace |
59 new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_pref
ix}}NS); | 71 new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_pref
ix}}NS); |
60 {% for name, tag_list in (tags + attrs)|groupby('name')|sort %} | 72 {% set tagnames = tags|map(attribute='name')|list() %} |
61 StringImpl* {{tag_list[0]|symbol}}Impl = StringImpl::createStatic("{{name}}"
, {{name|length}}, {{name|hash}}); | 73 {% set attrnames = attrs|map(attribute='name')|list() %} |
| 74 static const NameEntry kNames[] = { |
| 75 {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, ca
se_sensitive=True) %} |
| 76 { "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)|int
}}, {{ (name in attrnames)|int }} }, |
62 {% endfor %} | 77 {% endfor %} |
| 78 }; |
63 | 79 |
64 // Tags | 80 {% if tags %} |
65 {% for tag in tags|sort %} | 81 size_t tag_i = 0; |
66 QualifiedName::createStatic((void*)&{{tag|symbol}}Tag, {{tag|symbol}}Impl, {
{namespace_prefix}}NS); | 82 {% endif %} |
67 {% endfor %} | 83 size_t attr_i = 0; |
| 84 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) { |
| 85 StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames
[i].length, kNames[i].hash); |
| 86 {% if tags %} |
| 87 if (kNames[i].isTag) { |
| 88 void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suf
fix}}TagStorage) + tag_i; |
| 89 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}
}NS); |
| 90 tag_i++; |
| 91 } |
68 | 92 |
69 // Attrs | 93 if (!kNames[i].isAttr) |
70 {% for attr in attrs|sort %} | 94 continue; |
71 {% if use_namespace_for_attrs %} | 95 {% endif %} |
72 QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl
, {{namespace_prefix}}NS); | 96 void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage)
+ attr_i; |
73 {% else %} | 97 {% if use_namespace_for_attrs %} |
74 QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl
); | 98 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS)
; |
| 99 {% else %} |
| 100 QualifiedName::createStatic(address, stringImpl); |
| 101 {% endif %} |
| 102 attr_i++; |
| 103 } |
| 104 {% if tags %} |
| 105 ASSERT(tag_i == {{namespace}}TagsCount); |
75 {% endif %} | 106 {% endif %} |
76 {% endfor %} | 107 ASSERT(attr_i == {{namespace}}AttrsCount); |
77 } | 108 } |
78 | 109 |
79 } // {{namespace}} | 110 } // {{namespace}} |
80 } // namespace blink | 111 } // namespace blink |
OLD | NEW |