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

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: 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 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 char string_impl_storage[sizeof(StringImpl)];
67 char name[kMaxNameLength];
68 unsigned hash;
69 unsigned char length;
70 unsigned char isTag;
71 unsigned char isAttr;
72 };
73
74 static NameEntry Names[] = {
73 {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, ca se_sensitive=True) %} 75 {% 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 }} }, 76 { "", "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)| int }}, {{ (name in attrnames)|int }} },
75 {% endfor %} 77 {% endfor %}
76 }; 78 };
77 79
78 {% if tags %} 80 {% if tags %}
79 size_t tag_i = 0; 81 size_t tag_i = 0;
80 {% endif %} 82 {% endif %}
81 size_t attr_i = 0; 83 size_t attr_i = 0;
82 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) { 84 for (size_t i = 0; i < WTF_ARRAY_LENGTH(Names); i++) {
83 StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames [i].length, kNames[i].hash); 85 StringImpl* stringImpl = StringImpl::createPreallocatedStatic(Names[i].s tring_impl_storage, Names[i].length, Names[i].hash);
84 {% if tags %} 86 {% if tags %}
85 if (kNames[i].isTag) { 87 if (Names[i].isTag) {
86 void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suf fix}}TagStorage) + tag_i; 88 void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suf fix}}TagStorage) + tag_i;
87 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix} }NS); 89 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix} }NS);
88 tag_i++; 90 tag_i++;
89 } 91 }
90 92
91 if (!kNames[i].isAttr) 93 if (!Names[i].isAttr)
92 continue; 94 continue;
93 {% endif %} 95 {% endif %}
94 void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i; 96 void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i;
95 {% if use_namespace_for_attrs %} 97 {% if use_namespace_for_attrs %}
96 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS) ; 98 QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS) ;
97 {% else %} 99 {% else %}
98 QualifiedName::createStatic(address, stringImpl); 100 QualifiedName::createStatic(address, stringImpl);
99 {% endif %} 101 {% endif %}
100 attr_i++; 102 attr_i++;
101 } 103 }
102 {% if tags %} 104 {% if tags %}
103 ASSERT(tag_i == {{namespace}}TagsCount); 105 ASSERT(tag_i == {{namespace}}TagsCount);
104 {% endif %} 106 {% endif %}
105 ASSERT(attr_i == {{namespace}}AttrsCount); 107 ASSERT(attr_i == {{namespace}}AttrsCount);
106 } 108 }
107 109
108 } // {{namespace}} 110 } // {{namespace}}
109 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698