Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1782)

Unified Diff: Source/wtf/text/StringBuilder.cpp

Issue 212603003: De-bloat SVGPathStringBuilder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Drop ASSERT. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/text/StringBuilder.h ('k') | Source/wtf/text/StringBuilderTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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!
« no previous file with comments | « Source/wtf/text/StringBuilder.h ('k') | Source/wtf/text/StringBuilderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698