| Index: Source/wtf/text/StringBuilder.cpp
|
| diff --git a/Source/wtf/text/StringBuilder.cpp b/Source/wtf/text/StringBuilder.cpp
|
| index 8f3c522bdfdb4b400974d96f1e27837074dd668a..9236bf6fb55526c337cbc82ed4074f5da8cbc934 100644
|
| --- a/Source/wtf/text/StringBuilder.cpp
|
| +++ b/Source/wtf/text/StringBuilder.cpp
|
| @@ -29,6 +29,7 @@
|
|
|
| #include "IntegerToStringConversion.h"
|
| #include "WTFString.h"
|
| +#include "wtf/dtoa.h"
|
|
|
| namespace WTF {
|
|
|
| @@ -346,6 +347,35 @@ void StringBuilder::appendNumber(unsigned long long number)
|
| numberToStringUnsigned<StringBuilder>(number, this);
|
| }
|
|
|
| +static void expandLCharToUCharInplace(UChar* buffer, size_t length)
|
| +{
|
| + const LChar* sourceEnd = reinterpret_cast<LChar*>(buffer) + length;
|
| + UChar* current = buffer + length;
|
| + while (current != buffer)
|
| + *--current = *--sourceEnd;
|
| +}
|
| +
|
| +void StringBuilder::appendNumber(double number, unsigned precision, TrailingZerosTruncatingPolicy trailingZerosTruncatingPolicy)
|
| +{
|
| + bool truncateTrailingZeros = trailingZerosTruncatingPolicy == TruncateTrailingZeros;
|
| + size_t numberLength;
|
| + if (m_is8Bit) {
|
| + LChar* dest = appendUninitialized<LChar>(NumberToStringBufferLength);
|
| + const char* result = numberToFixedPrecisionString(number, precision, reinterpret_cast<char*>(dest), truncateTrailingZeros);
|
| + numberLength = strlen(result);
|
| + } else {
|
| + UChar* dest = appendUninitialized<UChar>(NumberToStringBufferLength);
|
| + const char* result = numberToFixedPrecisionString(number, precision, reinterpret_cast<char*>(dest), truncateTrailingZeros);
|
| + numberLength = strlen(result);
|
| + expandLCharToUCharInplace(dest, numberLength);
|
| + }
|
| + ASSERT(m_length >= NumberToStringBufferLength);
|
| + // Remove what appendUninitialized added.
|
| + m_length -= NumberToStringBufferLength;
|
| + ASSERT(numberLength <= NumberToStringBufferLength);
|
| + m_length += numberLength;
|
| +}
|
| +
|
| bool StringBuilder::canShrink() const
|
| {
|
| // Only shrink the buffer if it's less than 80% full. Need to tune this heuristic!
|
|
|