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

Unified Diff: Source/build/scripts/templates/MakeNames.cpp.tmpl

Issue 604743003: MakeNames: Generate global constants in a loop rather than in sequence. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: MakeNames: In a loop instead of in a sequence. Created 6 years, 3 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: Source/build/scripts/templates/MakeNames.cpp.tmpl
diff --git a/Source/build/scripts/templates/MakeNames.cpp.tmpl b/Source/build/scripts/templates/MakeNames.cpp.tmpl
index 27bad7d23aeb5cf5dbd3a557f3bb638c568248d9..8674a64558b7c2f0f17aba0d5bc1be29a93db7f2 100644
--- a/Source/build/scripts/templates/MakeNames.cpp.tmpl
+++ b/Source/build/scripts/templates/MakeNames.cpp.tmpl
@@ -5,32 +5,42 @@
#include "{{namespace}}{{suffix}}Names.h"
-#include "wtf/StaticConstructors.h"
+#include "wtf/StdLibExtras.h"
namespace blink {
namespace {{namespace}}Names {
using namespace WTF;
-{% for entry in entries|sort %}
+const int k{{suffix}}NameCount = {{entries|length}};
+
+void* {{suffix}}NamesStorage[k{{suffix}}NameCount * ((sizeof(AtomicString) + sizeof(void *) - 1) / sizeof(void *))];
+
+{% for entry in entries|sort(case_sensitive=True) %}
Jens Widell 2014/09/26 06:09:46 Since we're sorting a list of structures (not stri
Daniel Bratell 2014/09/26 07:59:28 Done.
{% filter enable_conditional(entry.Conditional) %}
-DEFINE_GLOBAL(AtomicString, {{entry|symbol}})
+const AtomicString& {{entry|symbol}} = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage)[{{loop.index0}}];
{% endfilter %}
{% endfor %}
void init{{suffix}}()
{
- {% for entry in entries|sort %}
- {% filter enable_conditional(entry.Conditional) %}
- StringImpl* {{entry|symbol}}Impl = StringImpl::createStatic("{{entry|cpp_name}}", {{entry|cpp_name|length}}, {{entry|cpp_name|hash}});
- {% endfilter %}
+ struct NameEntry {
+ const char* name;
+ unsigned hash;
+ unsigned char length;
+ };
+
+ static const NameEntry kNames[] = {
+ {% for entry in entries|sort(case_sensitive=True) %}
+ { "{{entry|cpp_name}}", {{entry|cpp_name|hash}}, {{entry|cpp_name|length}} },
Jens Widell 2014/09/26 06:09:46 I don't really understand why "|cpp_name" is used
Daniel Bratell 2014/09/26 07:59:29 I am not expert on this, but it seems that while M
Jens Widell 2014/09/26 08:44:57 Right. (I'm sorry I didn't fully investigate befor
{% endfor %}
+ };
- {% for entry in entries|sort %}
- {% filter enable_conditional(entry.Conditional) %}
- new ((void*)&{{entry|symbol}}) AtomicString({{entry|symbol}}Impl);
- {% endfilter %}
- {% 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);
+ void* address = reinterpret_cast<AtomicString*>(&{{suffix}}NamesStorage) + i;
+ new (address) AtomicString(stringImpl);
+ }
}
} // {{namespace}}Names

Powered by Google App Engine
This is Rietveld 408576698