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}}{{suffix}}Names.h" | 6 #include "{{namespace}}{{suffix}}Names.h" |
7 | 7 |
8 #include "wtf/StaticConstructors.h" | 8 #include "wtf/StdLibExtras.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 namespace {{namespace}}Names { | 11 namespace {{namespace}}Names { |
12 | 12 |
13 using namespace WTF; | 13 using namespace WTF; |
14 | 14 |
15 {% for entry in entries|sort %} | 15 const int k{{suffix}}NameCount = {{entries|length}}; |
| 16 |
| 17 void* {{suffix}}NamesStorage[k{{suffix}}NameCount * ((sizeof(AtomicString) + siz
eof(void *) - 1) / sizeof(void *))]; |
| 18 |
| 19 {% for entry in entries|sort(attribute='name', case_sensitive=True) %} |
16 {% filter enable_conditional(entry.Conditional) %} | 20 {% filter enable_conditional(entry.Conditional) %} |
17 DEFINE_GLOBAL(AtomicString, {{entry|symbol}}) | 21 const AtomicString& {{entry|symbol}} = reinterpret_cast<AtomicString*>(&{{suffix
}}NamesStorage)[{{loop.index0}}]; |
18 {% endfilter %} | 22 {% endfilter %} |
19 {% endfor %} | 23 {% endfor %} |
20 | 24 |
21 void init{{suffix}}() | 25 void init{{suffix}}() |
22 { | 26 { |
23 {% for entry in entries|sort %} | 27 struct NameEntry { |
24 {% filter enable_conditional(entry.Conditional) %} | 28 const char* name; |
25 StringImpl* {{entry|symbol}}Impl = StringImpl::createStatic("{{entry|cpp_nam
e}}", {{entry|cpp_name|length}}, {{entry|cpp_name|hash}}); | 29 unsigned hash; |
26 {% endfilter %} | 30 unsigned char length; |
| 31 }; |
| 32 |
| 33 static const NameEntry kNames[] = { |
| 34 {% for entry in entries|sort(attribute='name', case_sensitive=True) %} |
| 35 { "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|length
}} }, |
27 {% endfor %} | 36 {% endfor %} |
| 37 }; |
28 | 38 |
29 {% for entry in entries|sort %} | 39 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) { |
30 {% filter enable_conditional(entry.Conditional) %} | 40 StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames
[i].length, kNames[i].hash); |
31 new ((void*)&{{entry|symbol}}) AtomicString({{entry|symbol}}Impl); | 41 void* address = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage)
+ i; |
32 {% endfilter %} | 42 new (address) AtomicString(stringImpl); |
33 {% endfor %} | 43 } |
34 } | 44 } |
35 | 45 |
36 } // {{namespace}}Names | 46 } // {{namespace}}Names |
37 } // namespace blink | 47 } // namespace blink |
OLD | NEW |