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

Unified 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, 2 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
Index: third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl
diff --git a/third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl b/third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl
index ed0c03160f41f7ef42c01dc3f783c5c1a13ca419..2889987e7c57729a48b468e122b132a98c7dd274 100644
--- a/third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl
+++ b/third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl
@@ -27,20 +27,25 @@ const AtomicString& {{entry|symbol}} = reinterpret_cast<AtomicString*>(&{{suffix
void init{{suffix}}()
{
+ const int kMaxNameLength = {{entries|map(attribute='name')|map('length')|max}} + 1;
struct NameEntry {
- const char* name;
+ // StringImpl instances are created at |stringImplStorage| in-place.
+ // |name| must be placed soon after |stringImplStorage| to match the memory layout requirement of StringImpl.
+ char stringImplStorage[sizeof(StringImpl)];
+ char name[kMaxNameLength];
unsigned hash;
unsigned char length;
};
- static const NameEntry kNames[] = {
+ static NameEntry kNames[] = {
{% for entry in entries|sort(attribute='name', case_sensitive=True) %}
- { "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|length}} },
+ { "", "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|length}} },
{% endfor %}
};
for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
- StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames[i].length, kNames[i].hash);
+ StringImpl* stringImpl = StringImpl::createPreallocatedStatic(kNames[i].stringImplStorage, kNames[i].length, kNames[i].hash);
+ ASSERT(reinterpret_cast<char*>(stringImpl + 1) == kNames[i].name);
void* address = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage) + i;
new (address) AtomicString(stringImpl);
}

Powered by Google App Engine
This is Rietveld 408576698