Title: [125357] trunk/Source
Revision
125357
Author
[email protected]
Date
2012-08-11 14:17:27 -0700 (Sat, 11 Aug 2012)

Log Message

Do the DecimalNumber to String conversion on 8 bits
https://bugs.webkit.org/show_bug.cgi?id=93683

Patch by Benjamin Poulain <[email protected]> on 2012-08-11
Reviewed by Andreas Kling.

Source/WebCore: 

Numbers converted to string for CSS are unlikely to ever be concatenated with a 16bits string.
This patch change the conversion to be done to 8bits string in order to reduce memory allocations.

* css/CSSPrimitiveValue.cpp:
(WebCore::formatNumber):
* inspector/InspectorValues.cpp:
(WebCore::InspectorBasicValue::writeJSON):
* platform/graphics/Color.cpp:
(WebCore::Color::serialized): Instead of allocating a static WTF::String, we can simply append the
string literal to the output vector.

Source/WTF: 

Modify DecimalNumber to do the conversion to string on LChar instead of UChar.

* wtf/DecimalNumber.cpp:
(WTF::DecimalNumber::toStringDecimal):
(WTF::DecimalNumber::toStringExponential):
* wtf/DecimalNumber.h:
(DecimalNumber):
* wtf/dtoa.h:
* wtf/text/StringBuffer.h:
(WTF::StringBuffer::operator[]): StringBuffer::operator[] was incorrectly typed to UChar, making
the method impossible to instanciate with LChar.
* wtf/text/WTFString.h:
(String):
(WTF::String::adopt): String::adopt() is modified to work with both LChar and UChar. StringImpl
already support that.
(WTF::appendNumber): Add support for any type that can instanciate the template.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def (125356 => 125357)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def	2012-08-11 21:17:27 UTC (rev 125357)
@@ -352,8 +352,8 @@
     ?toObject@JSCell@JSC@@QBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
     ?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
     ?toString@JSObject@JSC@@QBEPAVJSString@2@PAVExecState@2@@Z
-    ?toStringDecimal@DecimalNumber@WTF@@QBEIPA_WI@Z
-    ?toStringExponential@DecimalNumber@WTF@@QBEIPA_WI@Z
+    ?toStringDecimal@DecimalNumber@WTF@@QBEIPAEI@Z
+    ?toStringExponential@DecimalNumber@WTF@@QBEIPAEI@Z
     ?toStringSlowCase@JSValue@JSC@@ABEPAVJSString@2@PAVExecState@2@@Z
     ?toThisObject@JSObject@JSC@@SAPAV12@PAVJSCell@2@PAVExecState@2@@Z
     ?toThisObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@@Z

Modified: trunk/Source/WTF/ChangeLog (125356 => 125357)


--- trunk/Source/WTF/ChangeLog	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/ChangeLog	2012-08-11 21:17:27 UTC (rev 125357)
@@ -1,3 +1,27 @@
+2012-08-11  Benjamin Poulain  <[email protected]>
+
+        Do the DecimalNumber to String conversion on 8 bits
+        https://bugs.webkit.org/show_bug.cgi?id=93683
+
+        Reviewed by Andreas Kling.
+
+        Modify DecimalNumber to do the conversion to string on LChar instead of UChar.
+
+        * wtf/DecimalNumber.cpp:
+        (WTF::DecimalNumber::toStringDecimal):
+        (WTF::DecimalNumber::toStringExponential):
+        * wtf/DecimalNumber.h:
+        (DecimalNumber):
+        * wtf/dtoa.h:
+        * wtf/text/StringBuffer.h:
+        (WTF::StringBuffer::operator[]): StringBuffer::operator[] was incorrectly typed to UChar, making
+        the method impossible to instanciate with LChar.
+        * wtf/text/WTFString.h:
+        (String):
+        (WTF::String::adopt): String::adopt() is modified to work with both LChar and UChar. StringImpl
+        already support that.
+        (WTF::appendNumber): Add support for any type that can instanciate the template.
+
 2012-08-11  Benjamin Poulain  <[email protected]>
 
         WebCore::findAtomicString(PropertyName) always convert the name to 16bits

Modified: trunk/Source/WTF/wtf/DecimalNumber.cpp (125356 => 125357)


--- trunk/Source/WTF/wtf/DecimalNumber.cpp	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/wtf/DecimalNumber.cpp	2012-08-11 21:17:27 UTC (rev 125357)
@@ -99,13 +99,13 @@
     return length;
 }
 
-unsigned DecimalNumber::toStringDecimal(UChar* buffer, unsigned bufferLength) const
+unsigned DecimalNumber::toStringDecimal(LChar* buffer, unsigned bufferLength) const
 {
     ASSERT_UNUSED(bufferLength, bufferLength >= bufferLengthForStringDecimal());
 
     // Should always be at least one digit to add to the string!
     ASSERT(m_precision);
-    UChar* next = buffer;
+    LChar* next = buffer;
 
     // if the exponent is negative the number decimal representation is of the form:
     // [<sign>]0.[<zeros>]<significand>
@@ -155,13 +155,13 @@
     return next - buffer;
 }
 
-unsigned DecimalNumber::toStringExponential(UChar* buffer, unsigned bufferLength) const
+unsigned DecimalNumber::toStringExponential(LChar* buffer, unsigned bufferLength) const
 {
     ASSERT_UNUSED(bufferLength, bufferLength >= bufferLengthForStringExponential());
 
     // Should always be at least one digit to add to the string!
     ASSERT(m_precision);
-    UChar* next = buffer;
+    LChar* next = buffer;
 
     // Add the sign
     if (m_sign)

Modified: trunk/Source/WTF/wtf/DecimalNumber.h (125356 => 125357)


--- trunk/Source/WTF/wtf/DecimalNumber.h	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/wtf/DecimalNumber.h	2012-08-11 21:17:27 UTC (rev 125357)
@@ -84,8 +84,8 @@
     WTF_EXPORT_PRIVATE unsigned bufferLengthForStringDecimal() const;
     WTF_EXPORT_PRIVATE unsigned bufferLengthForStringExponential() const;
 
-    WTF_EXPORT_PRIVATE unsigned toStringDecimal(UChar* buffer, unsigned bufferLength) const;
-    WTF_EXPORT_PRIVATE unsigned toStringExponential(UChar* buffer, unsigned bufferLength) const;
+    WTF_EXPORT_PRIVATE unsigned toStringDecimal(LChar* buffer, unsigned bufferLength) const;
+    WTF_EXPORT_PRIVATE unsigned toStringExponential(LChar* buffer, unsigned bufferLength) const;
 
     bool sign() const { return m_sign; }
     int exponent() const { return m_exponent; }

Modified: trunk/Source/WTF/wtf/dtoa.h (125356 => 125357)


--- trunk/Source/WTF/wtf/dtoa.h	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/wtf/dtoa.h	2012-08-11 21:17:27 UTC (rev 125357)
@@ -40,7 +40,7 @@
 // Size = 80 for sizeof(DtoaBuffer) + some sign bits, decimal point, 'e', exponent digits.
 const unsigned NumberToStringBufferLength = 96;
 typedef char NumberToStringBuffer[NumberToStringBufferLength];
-typedef UChar NumberToUStringBuffer[NumberToStringBufferLength];
+typedef LChar NumberToLStringBuffer[NumberToStringBufferLength];
 
 WTF_EXPORT_PRIVATE const char* numberToString(double, NumberToStringBuffer);
 WTF_EXPORT_PRIVATE const char* numberToFixedPrecisionString(double, unsigned significantFigures, NumberToStringBuffer, bool truncateTrailingZeros = false);
@@ -72,7 +72,7 @@
 } // namespace WTF
 
 using WTF::NumberToStringBuffer;
-using WTF::NumberToUStringBuffer;
+using WTF::NumberToLStringBuffer;
 using WTF::numberToString;
 using WTF::numberToFixedPrecisionString;
 using WTF::numberToFixedWidthString;

Modified: trunk/Source/WTF/wtf/text/StringBuffer.h (125356 => 125357)


--- trunk/Source/WTF/wtf/text/StringBuffer.h	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/wtf/text/StringBuffer.h	2012-08-11 21:17:27 UTC (rev 125357)
@@ -71,7 +71,7 @@
     unsigned length() const { return m_length; }
     CharType* characters() { return m_data; }
 
-    UChar& operator[](unsigned i) { ASSERT(i < m_length); return m_data[i]; }
+    CharType& operator[](unsigned i) { ASSERT(i < m_length); return m_data[i]; }
 
     CharType* release() { CharType* data = "" m_data = 0; return data; }
 

Modified: trunk/Source/WTF/wtf/text/WTFString.h (125356 => 125357)


--- trunk/Source/WTF/wtf/text/WTFString.h	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2012-08-11 21:17:27 UTC (rev 125357)
@@ -158,8 +158,8 @@
 
     static String adopt(StringBuffer<LChar>& buffer) { return StringImpl::adopt(buffer); }
     static String adopt(StringBuffer<UChar>& buffer) { return StringImpl::adopt(buffer); }
-    template<size_t inlineCapacity>
-    static String adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
+    template<typename CharacterType, size_t inlineCapacity>
+    static String adopt(Vector<CharacterType, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
 
     bool isNull() const { return !m_impl; }
     bool isEmpty() const { return !m_impl || !m_impl->length(); }
@@ -557,7 +557,8 @@
     vector.append(string.characters(), string.length());
 }
 
-inline void appendNumber(Vector<UChar>& vector, unsigned char number)
+template<typename CharacterType>
+inline void appendNumber(Vector<CharacterType>& vector, unsigned char number)
 {
     int numberLength = number > 99 ? 3 : (number > 9 ? 2 : 1);
     size_t vectorSize = vector.size();

Modified: trunk/Source/WebCore/ChangeLog (125356 => 125357)


--- trunk/Source/WebCore/ChangeLog	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WebCore/ChangeLog	2012-08-11 21:17:27 UTC (rev 125357)
@@ -1,3 +1,21 @@
+2012-08-11  Benjamin Poulain  <[email protected]>
+
+        Do the DecimalNumber to String conversion on 8 bits
+        https://bugs.webkit.org/show_bug.cgi?id=93683
+
+        Reviewed by Andreas Kling.
+
+        Numbers converted to string for CSS are unlikely to ever be concatenated with a 16bits string.
+        This patch change the conversion to be done to 8bits string in order to reduce memory allocations.
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::formatNumber):
+        * inspector/InspectorValues.cpp:
+        (WebCore::InspectorBasicValue::writeJSON):
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::serialized): Instead of allocating a static WTF::String, we can simply append the
+        string literal to the output vector.
+
 2012-08-11  Benjamin Poulain  <[email protected]>
 
         WebCore::findAtomicString(PropertyName) always convert the name to 16bits

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (125356 => 125357)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2012-08-11 21:17:27 UTC (rev 125357)
@@ -832,12 +832,12 @@
 {
     DecimalNumber decimal(number);
 
-    StringBuffer<UChar> buffer(decimal.bufferLengthForStringDecimal() + suffixLength);
+    StringBuffer<LChar> buffer(decimal.bufferLengthForStringDecimal() + suffixLength);
     unsigned length = decimal.toStringDecimal(buffer.characters(), buffer.length());
     ASSERT(length + suffixLength == buffer.length());
 
     for (unsigned i = 0; i < suffixLength; ++i)
-        buffer[length + i] = suffix[i];
+        buffer[length + i] = static_cast<LChar>(suffix[i]);
 
     return String::adopt(buffer);
 }

Modified: trunk/Source/WebCore/inspector/InspectorValues.cpp (125356 => 125357)


--- trunk/Source/WebCore/inspector/InspectorValues.cpp	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WebCore/inspector/InspectorValues.cpp	2012-08-11 21:17:27 UTC (rev 125357)
@@ -625,7 +625,7 @@
         else
             output->append(falseString, 5);
     } else if (type() == TypeNumber) {
-        NumberToUStringBuffer buffer;
+        NumberToLStringBuffer buffer;
         if (!isfinite(m_doubleValue)) {
             output->append(nullString, 4);
             return;

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (125356 => 125357)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2012-08-11 21:12:27 UTC (rev 125356)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2012-08-11 21:17:27 UTC (rev 125357)
@@ -182,9 +182,6 @@
 
 String Color::serialized() const
 {
-    DEFINE_STATIC_LOCAL(const String, commaSpace, (", "));
-    DEFINE_STATIC_LOCAL(const String, rgbaParen, ("rgba("));
-
     if (!hasAlpha()) {
         StringBuilder builder;
         builder.reserveCapacity(7);
@@ -195,21 +192,23 @@
         return builder.toString();
     }
 
-    Vector<UChar> result;
+    Vector<LChar> result;
     result.reserveInitialCapacity(28);
+    const char commaSpace[] = ", ";
+    const char rgbaParen[] = "rgba(";
 
-    append(result, rgbaParen);
+    result.append(rgbaParen, 5);
     appendNumber(result, red());
-    append(result, commaSpace);
+    result.append(commaSpace, 2);
     appendNumber(result, green());
-    append(result, commaSpace);
+    result.append(commaSpace, 2);
     appendNumber(result, blue());
-    append(result, commaSpace);
+    result.append(commaSpace, 2);
 
     if (!alpha())
         result.append('0');
     else {
-        NumberToUStringBuffer buffer;
+        NumberToLStringBuffer buffer;
         unsigned length = DecimalNumber(alpha() / 255.0).toStringDecimal(buffer, WTF::NumberToStringBufferLength);
         result.append(buffer, length);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to