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

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl

Issue 1405573003: Introduce StringImpl::createPreallocatedStatic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment. Removed StringImpl::createStatic. Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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/StdLibExtras.h" 8 #include "wtf/StdLibExtras.h"
9 9
10 // Generated from: 10 // Generated from:
11 {% for entry in in_files|sort %} 11 {% for entry in in_files|sort %}
12 // - {{entry}} 12 // - {{entry}}
13 {% endfor %} 13 {% endfor %}
14 14
15 namespace blink { 15 namespace blink {
16 namespace {{namespace}}Names { 16 namespace {{namespace}}Names {
17 17
18 using namespace WTF; 18 using namespace WTF;
19 19
20 void* {{suffix}}NamesStorage[{{namespace}}{{suffix}}NamesCount * ((sizeof(Atomic String) + sizeof(void *) - 1) / sizeof(void *))]; 20 void* {{suffix}}NamesStorage[{{namespace}}{{suffix}}NamesCount * ((sizeof(Atomic String) + sizeof(void *) - 1) / sizeof(void *))];
21 21
22 {% for entry in entries|sort(attribute='name', case_sensitive=True) %} 22 {% for entry in entries|sort(attribute='name', case_sensitive=True) %}
23 {% filter enable_conditional(entry.Conditional) %} 23 {% filter enable_conditional(entry.Conditional) %}
24 const AtomicString& {{entry|symbol}} = reinterpret_cast<AtomicString*>(&{{suffix }}NamesStorage)[{{loop.index0}}]; 24 const AtomicString& {{entry|symbol}} = reinterpret_cast<AtomicString*>(&{{suffix }}NamesStorage)[{{loop.index0}}];
25 {% endfilter %} 25 {% endfilter %}
26 {% endfor %} 26 {% endfor %}
27 27
28 void init{{suffix}}() 28 void init{{suffix}}()
29 { 29 {
30 const int kMaxNameLength = {{entries|map(attribute='name')|map('length')|max }} + 1;
30 struct NameEntry { 31 struct NameEntry {
31 const char* name; 32 // StringImpl instances are created at |stringImplStorage| in-place.
33 // |name| must be placed soon after |stringImplStorage| to match the mem ory layout requirement of StringImpl.
34 char stringImplStorage[sizeof(StringImpl)];
35 char name[kMaxNameLength];
32 unsigned hash; 36 unsigned hash;
33 unsigned char length; 37 unsigned char length;
34 }; 38 };
35 39
36 static const NameEntry kNames[] = { 40 static NameEntry kNames[] = {
37 {% for entry in entries|sort(attribute='name', case_sensitive=True) %} 41 {% for entry in entries|sort(attribute='name', case_sensitive=True) %}
38 { "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|length }} }, 42 { "", "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|le ngth}} },
39 {% endfor %} 43 {% endfor %}
40 }; 44 };
41 45
42 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) { 46 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
43 StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames [i].length, kNames[i].hash); 47 StringImpl* stringImpl = StringImpl::createPreallocatedStatic(kNames[i]. stringImplStorage, kNames[i].length, kNames[i].hash);
48 ASSERT(reinterpret_cast<char*>(stringImpl + 1) == kNames[i].name);
44 void* address = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage) + i; 49 void* address = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage) + i;
45 new (address) AtomicString(stringImpl); 50 new (address) AtomicString(stringImpl);
46 } 51 }
47 } 52 }
48 53
49 } // {{namespace}}Names 54 } // {{namespace}}Names
50 } // namespace blink 55 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698