OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os.path | 3 import os.path |
4 import re | 4 import re |
5 import subprocess | 5 import subprocess |
6 import sys | 6 import sys |
7 | 7 |
8 from in_file import InFile | 8 from in_file import InFile |
9 import in_generator | 9 import in_generator |
10 import license | 10 import license |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 #include "config.h" | 71 #include "config.h" |
72 #include "%(class_name)s.h" | 72 #include "%(class_name)s.h" |
73 #include "core/platform/HashTools.h" | 73 #include "core/platform/HashTools.h" |
74 #include <string.h> | 74 #include <string.h> |
75 | 75 |
76 #include "wtf/ASCIICType.h" | 76 #include "wtf/ASCIICType.h" |
77 #include "wtf/text/AtomicString.h" | 77 #include "wtf/text/AtomicString.h" |
78 #include "wtf/text/WTFString.h" | 78 #include "wtf/text/WTFString.h" |
79 | 79 |
80 namespace WebCore { | 80 namespace WebCore { |
81 const char* const propertyNameStrings[numCSSProperties] = { | 81 static const char propertyNameStringsPool[] = { |
82 %(property_name_strings)s | 82 %(property_name_strings)s |
83 }; | 83 }; |
84 | 84 |
| 85 static const unsigned short propertyNameStringsOffsets[] = { |
| 86 %(property_name_offsets)s |
| 87 }; |
| 88 |
85 %%} | 89 %%} |
86 %%struct-type | 90 %%struct-type |
87 struct Property; | 91 struct Property; |
88 %%omit-struct-type | 92 %%omit-struct-type |
89 %%language=C++ | 93 %%language=C++ |
90 %%readonly-tables | 94 %%readonly-tables |
91 %%global-table | 95 %%global-table |
92 %%compare-strncmp | 96 %%compare-strncmp |
93 %%define class-name %(class_name)sHash | 97 %%define class-name %(class_name)sHash |
94 %%define lookup-function-name findPropertyImpl | 98 %%define lookup-function-name findPropertyImpl |
95 %%define hash-function-name propery_hash_function | 99 %%define hash-function-name propery_hash_function |
| 100 %%define slot-name nameOffset |
96 %%define word-array-name property_wordlist | 101 %%define word-array-name property_wordlist |
97 %%enum | 102 %%enum |
98 %%%% | 103 %%%% |
99 %(property_to_enum_map)s | 104 %(property_to_enum_map)s |
100 %%%% | 105 %%%% |
101 const Property* findProperty(register const char* str, register unsigned int len
) | 106 const Property* findProperty(register const char* str, register unsigned int len
) |
102 { | 107 { |
103 return %(class_name)sHash::findPropertyImpl(str, len); | 108 return %(class_name)sHash::findPropertyImpl(str, len); |
104 } | 109 } |
105 | 110 |
106 const char* getPropertyName(CSSPropertyID id) | 111 const char* getPropertyName(CSSPropertyID id) |
107 { | 112 { |
108 if (id < firstCSSProperty) | 113 if (id < firstCSSProperty) |
109 return 0; | 114 return 0; |
110 int index = id - firstCSSProperty; | 115 int index = id - firstCSSProperty; |
111 if (index >= numCSSProperties) | 116 if (index >= numCSSProperties) |
112 return 0; | 117 return 0; |
113 return propertyNameStrings[index]; | 118 return propertyNameStringsPool + propertyNameStringsOffsets[index]; |
114 } | 119 } |
115 | 120 |
116 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) | 121 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) |
117 { | 122 { |
118 if (id < firstCSSProperty) | 123 if (id < firstCSSProperty) |
119 return nullAtom; | 124 return nullAtom; |
120 int index = id - firstCSSProperty; | 125 int index = id - firstCSSProperty; |
121 if (index >= numCSSProperties) | 126 if (index >= numCSSProperties) |
122 return nullAtom; | 127 return nullAtom; |
123 | 128 |
124 static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; /
/ Intentionally never destroyed. | 129 static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; /
/ Intentionally never destroyed. |
125 AtomicString& propertyString = propertyStrings[index]; | 130 AtomicString& propertyString = propertyStrings[index]; |
126 if (propertyString.isNull()) { | 131 if (propertyString.isNull()) { |
127 const char* propertyName = propertyNameStrings[index]; | 132 const char* propertyName = propertyNameStringsPool + propertyNameStrings
Offsets[index]; |
128 propertyString = AtomicString(propertyName, strlen(propertyName), Atomic
String::ConstructFromLiteral); | 133 propertyString = AtomicString(propertyName, strlen(propertyName), Atomic
String::ConstructFromLiteral); |
129 } | 134 } |
130 return propertyString; | 135 return propertyString; |
131 } | 136 } |
132 | 137 |
133 String getPropertyNameString(CSSPropertyID id) | 138 String getPropertyNameString(CSSPropertyID id) |
134 { | 139 { |
135 // We share the StringImpl with the AtomicStrings. | 140 // We share the StringImpl with the AtomicStrings. |
136 return getPropertyNameAtomicString(id).string(); | 141 return getPropertyNameAtomicString(id).string(); |
137 } | 142 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 'license': license.license_for_generated_cpp(), | 208 'license': license.license_for_generated_cpp(), |
204 'class_name': self.class_name, | 209 'class_name': self.class_name, |
205 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties)), | 210 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties)), |
206 'first_property_id': self._first_property_id, | 211 'first_property_id': self._first_property_id, |
207 'properties_count': len(self._properties), | 212 'properties_count': len(self._properties), |
208 'last_property_id': self._first_property_id + len(self._properties)
- 1, | 213 'last_property_id': self._first_property_id + len(self._properties)
- 1, |
209 'max_name_length': reduce(max, map(len, map(lambda property: propert
y['name'], self._properties))), | 214 'max_name_length': reduce(max, map(len, map(lambda property: propert
y['name'], self._properties))), |
210 } | 215 } |
211 | 216 |
212 def generate_implementation(self): | 217 def generate_implementation(self): |
| 218 property_offsets = [] |
| 219 current_offset = 0 |
| 220 for property in self._properties: |
| 221 property_offsets.append(current_offset) |
| 222 current_offset += len(property["name"]) + 1 |
| 223 |
213 gperf_input = GPERF_TEMPLATE % { | 224 gperf_input = GPERF_TEMPLATE % { |
214 'license': license.license_for_generated_cpp(), | 225 'license': license.license_for_generated_cpp(), |
215 'class_name': self.class_name, | 226 'class_name': self.class_name, |
216 'property_name_strings': '\n'.join(map(lambda property: ' "%(name
)s",' % property, self._properties)), | 227 'property_name_strings': '\n'.join(map(lambda property: ' "%(name
)s\\0"' % property, self._properties)), |
| 228 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of
fset, property_offsets)), |
217 'property_to_enum_map': '\n'.join(map(lambda property: '%(name)s, %(
enum_name)s' % property, self._properties + self._aliases)), | 229 'property_to_enum_map': '\n'.join(map(lambda property: '%(name)s, %(
enum_name)s' % property, self._properties + self._aliases)), |
218 } | 230 } |
219 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 231 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
220 gperf_args = ['gperf', '--key-positions=*', '-D', '-n', '-s', '2'] | 232 gperf_args = ['gperf', '--key-positions=*', '-P', '-D', '-n', '-s', '2'] |
221 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE) | 233 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE) |
222 return gperf.communicate(gperf_input)[0] | 234 return gperf.communicate(gperf_input)[0] |
223 | 235 |
224 | 236 |
225 if __name__ == "__main__": | 237 if __name__ == "__main__": |
226 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) | 238 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) |
OLD | NEW |