Changeset 106724 in webkit
- Timestamp:
- Feb 3, 2012, 5:59:41 PM (15 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
bindings/js/JSCSSStyleDeclarationCustom.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r106723 r106724 1 2012-02-03 Benjamin Poulain <bpoulain@apple.com> 2 3 Reduce the memory allocations of WebCore's cssPropertyName() 4 https://bugs.webkit.org/show_bug.cgi?id=74782 5 6 Reviewed by Geoffrey Garen. 7 8 Add a fast path to avoid the use of the StringBuilder. 9 10 The string builder is needed for two cases: 11 -CSS prefix (the character after the prefix must be uppercase) 12 -JavaScript CamelCase name for CSS properties 13 14 We can skip all memory allocations if the property is not in those 15 two cases. We start by testing the string for uppercase characters, 16 and just return the an identical string. 17 18 This patch create a "fast case" 2.7 times faster than previously. 19 The "slow case" is 2-3% slower due to the additional check at the beginning. 20 21 * bindings/js/JSCSSStyleDeclarationCustom.cpp: 22 (WebCore): 23 (WebCore::containsASCIIUpperChar): 24 (WebCore::cssPropertyName): 25 (WebCore::isCSSPropertyName): 26 1 27 2012-02-03 Anders Carlsson <andersca@apple.com> 2 28 -
trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
r106695 r106724 139 139 } 140 140 141 template<typename CharacterType> 142 static inline bool containsASCIIUpperChar(const CharacterType* string, size_t length) 143 { 144 for (unsigned i = 0; i < length; ++i) { 145 if (isASCIIUpper(string[i])) 146 return true; 147 } 148 return false; 149 } 150 151 static inline bool containsASCIIUpperChar(const StringImpl& string) 152 { 153 if (string.is8Bit()) 154 return containsASCIIUpperChar(string.characters8(), string.length()); 155 return containsASCIIUpperChar(string.characters16(), string.length()); 156 } 157 141 158 static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) 142 159 { … … 148 165 return String(); 149 166 167 StringImpl* propertyNameString = propertyName.impl(); 168 // If there is no uppercase character in the propertyName, there can 169 // be no prefix, nor extension and we can return the same string. 170 if (!containsASCIIUpperChar(*propertyNameString)) 171 return String(propertyNameString); 172 150 173 StringBuilder builder; 151 174 builder.reserveCapacity(length); 152 175 153 const StringImpl* propertyNameString = propertyName.impl();154 176 unsigned i = 0; 155 177 switch (getCSSPropertyNamePrefix(*propertyNameString)) { … … 178 200 } 179 201 180 builder.append(toASCIILower( propertyName.characters()[i++]));202 builder.append(toASCIILower((*propertyNameString)[i++])); 181 203 182 204 for (; i < length; ++i) { 183 UChar c = propertyName.characters()[i];205 UChar c = (*propertyNameString)[i]; 184 206 if (!isASCIIUpper(c)) 185 207 builder.append(c); … … 193 215 static bool isCSSPropertyName(const Identifier& propertyIdentifier) 194 216 { 195 // FIXME: This mallocs a string for the property name and then throws it196 // away. This shows up on peacekeeper's domDynamicCreationCreateElement.197 217 return cssPropertyID(cssPropertyName(propertyIdentifier)); 198 218 }
Note:
See TracChangeset
for help on using the changeset viewer.