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

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/MakeQualifiedNames.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}}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 #include "wtf/StdLibExtras.h"
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName *[{{namespace}}AttrsCount]); 47 OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName *[{{namespace}}AttrsCount]);
48 for (size_t i = 0; i < {{namespace}}AttrsCount; i++) 48 for (size_t i = 0; i < {{namespace}}AttrsCount; i++)
49 attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i; 49 attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i;
50 return attrs.release(); 50 return attrs.release();
51 } 51 }
52 {% endif %} 52 {% endif %}
53 53
54 54
55 void init() 55 void init()
56 { 56 {
57 struct NameEntry {
58 const char* name;
59 unsigned hash;
60 unsigned char length;
61 unsigned char isTag;
62 unsigned char isAttr;
63 };
64
65 // Use placement new to initialize the globals. 57 // Use placement new to initialize the globals.
66 AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::Const ructFromLiteral); 58 AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::Const ructFromLiteral);
67 59
68 // Namespace 60 // Namespace
69 new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_pref ix}}NS); 61 new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_pref ix}}NS);
70 {% set tagnames = tags|map(attribute='name')|list() %} 62 {% set tagnames = tags|map(attribute='name')|list() %}
71 {% set attrnames = attrs|map(attribute='name')|list() %} 63 {% set attrnames = attrs|map(attribute='name')|list() %}
72 static const NameEntry kNames[] = { 64 const int kMaxNameLength = {{(tagnames + attrnames)|map('length')|max}} + 1;
65 struct NameEntry {
66 // StringImpl instances are created at |stringImplStorage| in-place.
67 // |name| must be placed soon after |stringImplStorage| to match the mem ory layout requirement of StringImpl.
68 char stringImplStorage[sizeof(StringImpl)];
69 char name[kMaxNameLength];
70 unsigned hash;
71 unsigned char length;
72 unsigned char isTag;
73 unsigned char isAttr;
74 };
75
76 static NameEntry kNames[] = {
73 {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, ca se_sensitive=True) %} 77 {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, ca se_sensitive=True) %}
74 { "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)|int }}, {{ (name in attrnames)|int }} }, 78 { "", "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)| int }}, {{ (name in attrnames)|int }} },
75 {% endfor %} 79 {% endfor %}
76 }; 80 };
77 81
78 {% if tags %} 82 {% if tags %}
79 size_t tag_i = 0; 83 size_t tag_i = 0;
80 {% endif %} 84 {% endif %}
81 size_t attr_i = 0; 85 size_t attr_i = 0;
82 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) { 86 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
83 StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames [i].length, kNames[i].hash); 87 StringImpl* stringImpl = StringImpl::createPreallocatedStatic(kNames[i]. stringImplStorage, kNames[i].length, kNames[i].hash);
84 {% if tags %} 88 {% if tags %}
85 if (kNames[i].isTag) { 89 if (kNames[i].isTag) {
86 void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suf fix}}TagStorage) + tag_i; 90 void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suf fix}}TagStorage) + tag_i;
87 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix} }NS); 91 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix} }NS);
88 tag_i++; 92 tag_i++;
89 } 93 }
90 94
91 if (!kNames[i].isAttr) 95 if (!kNames[i].isAttr)
92 continue; 96 continue;
93 {% endif %} 97 {% endif %}
94 void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i; 98 void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i;
95 {% if use_namespace_for_attrs %} 99 {% if use_namespace_for_attrs %}
96 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS) ; 100 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS) ;
97 {% else %} 101 {% else %}
98 QualifiedName::createStatic(address, stringImpl); 102 QualifiedName::createStatic(address, stringImpl);
99 {% endif %} 103 {% endif %}
100 attr_i++; 104 attr_i++;
101 } 105 }
102 {% if tags %} 106 {% if tags %}
103 ASSERT(tag_i == {{namespace}}TagsCount); 107 ASSERT(tag_i == {{namespace}}TagsCount);
104 {% endif %} 108 {% endif %}
105 ASSERT(attr_i == {{namespace}}AttrsCount); 109 ASSERT(attr_i == {{namespace}}AttrsCount);
106 } 110 }
107 111
108 } // {{namespace}} 112 } // {{namespace}}
109 } // namespace blink 113 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/build/scripts/templates/MakeNames.cpp.tmpl ('k') | third_party/WebKit/Source/wtf/text/StringImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698