Title: [106724] trunk/Source/WebCore
- Revision
- 106724
- Author
- [email protected]
- Date
- 2012-02-03 17:59:41 -0800 (Fri, 03 Feb 2012)
Log Message
Reduce the memory allocations of WebCore's cssPropertyName()
https://bugs.webkit.org/show_bug.cgi?id=74782
Patch by Benjamin Poulain <[email protected]> on 2012-02-03
Reviewed by Geoffrey Garen.
Add a fast path to avoid the use of the StringBuilder.
The string builder is needed for two cases:
-CSS prefix (the character after the prefix must be uppercase)
-_javascript_ CamelCase name for CSS properties
We can skip all memory allocations if the property is not in those
two cases. We start by testing the string for uppercase characters,
and just return the an identical string.
This patch create a "fast case" 2.7 times faster than previously.
The "slow case" is 2-3% slower due to the additional check at the beginning.
* bindings/js/JSCSSStyleDeclarationCustom.cpp:
(WebCore):
(WebCore::containsASCIIUpperChar):
(WebCore::cssPropertyName):
(WebCore::isCSSPropertyName):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (106723 => 106724)
--- trunk/Source/WebCore/ChangeLog 2012-02-04 01:56:42 UTC (rev 106723)
+++ trunk/Source/WebCore/ChangeLog 2012-02-04 01:59:41 UTC (rev 106724)
@@ -1,3 +1,29 @@
+2012-02-03 Benjamin Poulain <[email protected]>
+
+ Reduce the memory allocations of WebCore's cssPropertyName()
+ https://bugs.webkit.org/show_bug.cgi?id=74782
+
+ Reviewed by Geoffrey Garen.
+
+ Add a fast path to avoid the use of the StringBuilder.
+
+ The string builder is needed for two cases:
+ -CSS prefix (the character after the prefix must be uppercase)
+ -_javascript_ CamelCase name for CSS properties
+
+ We can skip all memory allocations if the property is not in those
+ two cases. We start by testing the string for uppercase characters,
+ and just return the an identical string.
+
+ This patch create a "fast case" 2.7 times faster than previously.
+ The "slow case" is 2-3% slower due to the additional check at the beginning.
+
+ * bindings/js/JSCSSStyleDeclarationCustom.cpp:
+ (WebCore):
+ (WebCore::containsASCIIUpperChar):
+ (WebCore::cssPropertyName):
+ (WebCore::isCSSPropertyName):
+
2012-02-03 Anders Carlsson <[email protected]>
WebKit2 should dispatch wheel events to the new ScrollingTree class
Modified: trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp (106723 => 106724)
--- trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp 2012-02-04 01:56:42 UTC (rev 106723)
+++ trunk/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp 2012-02-04 01:59:41 UTC (rev 106724)
@@ -138,6 +138,23 @@
return PropertyNamePrefixNone;
}
+template<typename CharacterType>
+static inline bool containsASCIIUpperChar(const CharacterType* string, size_t length)
+{
+ for (unsigned i = 0; i < length; ++i) {
+ if (isASCIIUpper(string[i]))
+ return true;
+ }
+ return false;
+}
+
+static inline bool containsASCIIUpperChar(const StringImpl& string)
+{
+ if (string.is8Bit())
+ return containsASCIIUpperChar(string.characters8(), string.length());
+ return containsASCIIUpperChar(string.characters16(), string.length());
+}
+
static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0)
{
if (hadPixelOrPosPrefix)
@@ -147,10 +164,15 @@
if (!length)
return String();
+ StringImpl* propertyNameString = propertyName.impl();
+ // If there is no uppercase character in the propertyName, there can
+ // be no prefix, nor extension and we can return the same string.
+ if (!containsASCIIUpperChar(*propertyNameString))
+ return String(propertyNameString);
+
StringBuilder builder;
builder.reserveCapacity(length);
- const StringImpl* propertyNameString = propertyName.impl();
unsigned i = 0;
switch (getCSSPropertyNamePrefix(*propertyNameString)) {
case PropertyNamePrefixNone:
@@ -177,10 +199,10 @@
builder.append('-');
}
- builder.append(toASCIILower(propertyName.characters()[i++]));
+ builder.append(toASCIILower((*propertyNameString)[i++]));
for (; i < length; ++i) {
- UChar c = propertyName.characters()[i];
+ UChar c = (*propertyNameString)[i];
if (!isASCIIUpper(c))
builder.append(c);
else
@@ -192,8 +214,6 @@
static bool isCSSPropertyName(const Identifier& propertyIdentifier)
{
- // FIXME: This mallocs a string for the property name and then throws it
- // away. This shows up on peacekeeper's domDynamicCreationCreateElement.
return cssPropertyID(cssPropertyName(propertyIdentifier));
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes