Chromium Code Reviews| Index: Source/wtf/text/StringBuilder.cpp |
| diff --git a/Source/wtf/text/StringBuilder.cpp b/Source/wtf/text/StringBuilder.cpp |
| index 8f3c522bdfdb4b400974d96f1e27837074dd668a..04cccc1c6258cbfc22724f617d258a06fea400cf 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,36 @@ 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; |
| + ASSERT(current == buffer); |
|
abarth-chromium
2014/03/28 17:41:43
This ASSERT seems unnecessary. That's the only wa
fs
2014/03/31 07:41:56
Dropped.
|
| +} |
| + |
| +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); |
|
abarth-chromium
2014/03/28 17:41:43
Woah
|
| + } |
| + 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! |