Commit 4d255977 authored by paroga@webkit.org's avatar paroga@webkit.org

Add StringBuilder::appendNumber() and use it

https://bugs.webkit.org/show_bug.cgi?id=96030

Reviewed by Eric Seidel.

Also fix a bunch of append() vs. appendLiteral() issues in the surrounding code.

Source/JavaScriptCore:

* API/JSContextRef.cpp:
(JSContextCreateBacktrace):
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
* interpreter/Interpreter.h:
(JSC::StackFrame::toString):

Source/WebCore:

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::hostName):
* bindings/v8/ScriptController.cpp:
(WebCore::resourceString):
* css/FontFeatureValue.cpp:
(WebCore::FontFeatureValue::customCssText):
* dom/Position.cpp:
(WebCore::Position::formatForDebugger):
* dom/Range.cpp:
(WebCore::Range::formatForDebugger):
* html/FormController.cpp:
(WebCore::FormKeyGenerator::formKey):
* html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::font):
* inspector/IdentifiersFactory.cpp:
(WebCore::IdentifiersFactory::addProcessIdPrefixTo):
* page/FrameTree.cpp:
(WebCore::FrameTree::uniqueChildName):
* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::toRawString):
* platform/Decimal.cpp:
(WebCore::Decimal::toString):
* platform/network/ProxyServer.cpp:
(WebCore::appendProxyServerString):
* platform/text/TextStream.cpp:
(WebCore::TextStream::operator<<):
* platform/text/TextStream.h:
* rendering/RenderTreeAsText.cpp:
(WebCore::nodePosition):
* xml/XMLErrors.cpp:
(WebCore::XMLErrors::appendErrorMessage):

Source/WTF:

* wtf/DateMath.cpp:
(WTF::makeRFC2822DateString):
* wtf/text/StringBuilder.cpp:
(WTF::StringBuilder::appendNumber):
* wtf/text/StringBuilder.h:
(StringBuilder):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128014 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9c1ffd6a
......@@ -200,15 +200,15 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
}
unsigned lineNumber = signedLineNumber >= 0 ? signedLineNumber : 0;
if (!builder.isEmpty())
builder.append("\n");
builder.append("#");
builder.append('\n');
builder.append('#');
builder.append(levelStr);
builder.append(" ");
builder.append(' ');
builder.append(functionName);
builder.append("() at ");
builder.appendLiteral("() at ");
builder.append(urlString);
builder.append(":");
builder.append(String::number(lineNumber));
builder.append(':');
builder.appendNumber(lineNumber);
if (!function || ++count == maxStackSize)
break;
callFrame = callFrame->callerFrame();
......
2012-09-09 Patrick Gansterer <paroga@webkit.org>
Add StringBuilder::appendNumber() and use it
https://bugs.webkit.org/show_bug.cgi?id=96030
Reviewed by Eric Seidel.
Also fix a bunch of append() vs. appendLiteral() issues in the surrounding code.
* API/JSContextRef.cpp:
(JSContextCreateBacktrace):
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
* interpreter/Interpreter.h:
(JSC::StackFrame::toString):
2012-09-09 Patrick Gansterer <paroga@webkit.org>
Make the String initialization on the function side of String::number()
......
......@@ -66,6 +66,12 @@ EXPORTS
?allocateSlowCase@MarkedAllocator@JSC@@AAEPAXXZ
?append@StringBuilder@WTF@@QAEXPBEI@Z
?append@StringBuilder@WTF@@QAEXPB_WI@Z
?appendNumber@StringBuilder@WTF@@QAEXH@Z
?appendNumber@StringBuilder@WTF@@QAEXI@Z
?appendNumber@StringBuilder@WTF@@QAEXJ@Z
?appendNumber@StringBuilder@WTF@@QAEXK@Z
?appendNumber@StringBuilder@WTF@@QAEX_J@Z
?appendNumber@StringBuilder@WTF@@QAEX_K@Z
?attach@Debugger@JSC@@QAEXPAVJSGlobalObject@2@@Z
?base64Decode@WTF@@YA_NABVString@1@AAV?$Vector@D$0A@@1@W4Base64DecodePolicy@1@@Z
?base64Encode@WTF@@YA?AVString@1@PBDIW4Base64EncodePolicy@1@@Z
......
......@@ -92,7 +92,7 @@ namespace JSC {
traceBuild.append(sourceURL);
if (line > -1) {
traceBuild.append(':');
traceBuild.append(String::number(line));
traceBuild.appendNumber(line);
}
}
return traceBuild.toString().impl();
......
2012-09-09 Patrick Gansterer <paroga@webkit.org>
Add StringBuilder::appendNumber() and use it
https://bugs.webkit.org/show_bug.cgi?id=96030
Reviewed by Eric Seidel.
Also fix a bunch of append() vs. appendLiteral() issues in the surrounding code.
* wtf/DateMath.cpp:
(WTF::makeRFC2822DateString):
* wtf/text/StringBuilder.cpp:
(WTF::StringBuilder::appendNumber):
* wtf/text/StringBuilder.h:
(StringBuilder):
2012-09-09 Patrick Gansterer <paroga@webkit.org>
Make the String initialization on the function side of String::number()
......
......@@ -1072,13 +1072,13 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u
{
StringBuilder stringBuilder;
stringBuilder.append(weekdayName[dayOfWeek]);
stringBuilder.append(", ");
stringBuilder.append(String::number(day));
stringBuilder.append(" ");
stringBuilder.appendLiteral(", ");
stringBuilder.appendNumber(day);
stringBuilder.append(' ');
stringBuilder.append(monthName[month]);
stringBuilder.append(" ");
stringBuilder.append(String::number(year));
stringBuilder.append(" ");
stringBuilder.append(' ');
stringBuilder.appendNumber(year);
stringBuilder.append(' ');
stringBuilder.append(twoDigitStringFromNumber(hours));
stringBuilder.append(':');
......@@ -1087,7 +1087,7 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u
stringBuilder.append(twoDigitStringFromNumber(seconds));
stringBuilder.append(' ');
stringBuilder.append(utcOffset > 0 ? "+" : "-");
stringBuilder.append(utcOffset > 0 ? '+' : '-');
int absoluteUTCOffset = abs(utcOffset);
stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset / 60));
stringBuilder.append(twoDigitStringFromNumber(absoluteUTCOffset % 60));
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include "StringBuilder.h"
#include "IntegerToStringConversion.h"
#include "WTFString.h"
namespace WTF {
......@@ -286,6 +287,36 @@ void StringBuilder::append(const LChar* characters, unsigned length)
}
}
void StringBuilder::appendNumber(int number)
{
numberToStringSigned<StringBuilder>(number, this);
}
void StringBuilder::appendNumber(unsigned int number)
{
numberToStringUnsigned<StringBuilder>(number, this);
}
void StringBuilder::appendNumber(long number)
{
numberToStringSigned<StringBuilder>(number, this);
}
void StringBuilder::appendNumber(unsigned long number)
{
numberToStringUnsigned<StringBuilder>(number, this);
}
void StringBuilder::appendNumber(long long number)
{
numberToStringSigned<StringBuilder>(number, this);
}
void StringBuilder::appendNumber(unsigned long long number)
{
numberToStringUnsigned<StringBuilder>(number, this);
}
bool StringBuilder::canShrink() const
{
// Only shrink the buffer if it's less than 80% full. Need to tune this heuristic!
......
......@@ -124,7 +124,7 @@ public:
} else
append(&c, 1);
}
void append(char c)
{
append(static_cast<LChar>(c));
......@@ -133,6 +133,13 @@ public:
template<unsigned charactersCount>
ALWAYS_INLINE void appendLiteral(const char (&characters)[charactersCount]) { append(characters, charactersCount - 1); }
WTF_EXPORT_PRIVATE void appendNumber(int);
WTF_EXPORT_PRIVATE void appendNumber(unsigned int);
WTF_EXPORT_PRIVATE void appendNumber(long);
WTF_EXPORT_PRIVATE void appendNumber(unsigned long);
WTF_EXPORT_PRIVATE void appendNumber(long long);
WTF_EXPORT_PRIVATE void appendNumber(unsigned long long);
String toString()
{
shrinkToFit();
......
2012-09-09 Patrick Gansterer <paroga@webkit.org>
Add StringBuilder::appendNumber() and use it
https://bugs.webkit.org/show_bug.cgi?id=96030
Reviewed by Eric Seidel.
Also fix a bunch of append() vs. appendLiteral() issues in the surrounding code.
* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::hostName):
* bindings/v8/ScriptController.cpp:
(WebCore::resourceString):
* css/FontFeatureValue.cpp:
(WebCore::FontFeatureValue::customCssText):
* dom/Position.cpp:
(WebCore::Position::formatForDebugger):
* dom/Range.cpp:
(WebCore::Range::formatForDebugger):
* html/FormController.cpp:
(WebCore::FormKeyGenerator::formKey):
* html/HTMLAnchorElement.cpp:
(WebCore::appendServerMapMousePosition):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::font):
* inspector/IdentifiersFactory.cpp:
(WebCore::IdentifiersFactory::addProcessIdPrefixTo):
* page/FrameTree.cpp:
(WebCore::FrameTree::uniqueChildName):
* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::toRawString):
* platform/Decimal.cpp:
(WebCore::Decimal::toString):
* platform/network/ProxyServer.cpp:
(WebCore::appendProxyServerString):
* platform/text/TextStream.cpp:
(WebCore::TextStream::operator<<):
* platform/text/TextStream.h:
* rendering/RenderTreeAsText.cpp:
(WebCore::nodePosition):
* xml/XMLErrors.cpp:
(WebCore::XMLErrors::appendErrorMessage):
2012-09-09 KyungTae Kim <ktf.kim@samsung.com>
[EFL] Wrong rendering results for square-button-appearance.html
......@@ -85,7 +85,7 @@ static String hostName(const KURL& url, bool secure)
builder.append(url.host().lower());
if (url.port() && ((!secure && url.port() != 80) || (secure && url.port() != 443))) {
builder.append(':');
builder.append(String::number(url.port()));
builder.appendNumber(url.port());
}
return builder.toString();
}
......
......@@ -220,7 +220,7 @@ static inline String resourceString(const v8::Handle<v8::Function> function)
StringBuilder builder;
builder.append(resourceName);
builder.append(':');
builder.append(String::number(lineNumber));
builder.appendNumber(lineNumber);
return builder.toString();
}
......
......@@ -43,10 +43,10 @@ FontFeatureValue::FontFeatureValue(const String& tag, int value)
String FontFeatureValue::customCssText() const
{
StringBuilder builder;
builder.append("'");
builder.append('\'');
builder.append(m_tag);
builder.append("' ");
builder.append(String::number(m_value));
builder.appendLiteral("' ");
builder.appendNumber(m_value);
return builder.toString();
}
......
......@@ -1321,7 +1321,7 @@ void Position::formatForDebugger(char* buffer, unsigned length) const
else {
char s[1024];
result.appendLiteral("offset ");
result.append(String::number(m_offset));
result.appendNumber(m_offset);
result.appendLiteral(" of ");
deprecatedNode()->formatForDebugger(s, sizeof(s));
result.append(s);
......
......@@ -1663,12 +1663,12 @@ void Range::formatForDebugger(char* buffer, unsigned length) const
const int FormatBufferSize = 1024;
char s[FormatBufferSize];
result.appendLiteral("from offset ");
result.append(String::number(m_start.offset()));
result.appendNumber(m_start.offset());
result.appendLiteral(" of ");
m_start.container()->formatForDebugger(s, FormatBufferSize);
result.append(s);
result.appendLiteral(" to offset ");
result.append(String::number(m_end.offset()));
result.appendNumber(m_end.offset());
result.appendLiteral(" of ");
m_end.container()->formatForDebugger(s, FormatBufferSize);
result.append(s);
......
......@@ -358,8 +358,8 @@ AtomicString FormKeyGenerator::formKey(const HTMLFormControlElementWithState& co
StringBuilder builder;
builder.append(signature);
builder.append(" #");
builder.append(String::number(nextIndex));
builder.appendLiteral(" #");
builder.appendNumber(nextIndex);
AtomicString formKey = builder.toAtomicString();
m_formToKeyMap.add(form, formKey);
return formKey;
......
......@@ -145,9 +145,9 @@ static void appendServerMapMousePosition(StringBuilder& url, Event* event)
int x = absolutePosition.x();
int y = absolutePosition.y();
url.append('?');
url.append(String::number(x));
url.appendNumber(x);
url.append(',');
url.append(String::number(y));
url.appendNumber(y);
}
void HTMLAnchorElement::defaultEventHandler(Event* event)
......
......@@ -2001,7 +2001,7 @@ String CanvasRenderingContext2D::font() const
if (fontDescription.smallCaps() == FontSmallCapsOn)
serializedFont.appendLiteral("small-caps ");
serializedFont.append(String::number(fontDescription.computedPixelSize()));
serializedFont.appendNumber(fontDescription.computedPixelSize());
serializedFont.appendLiteral("px");
const FontFamily& firstFontFamily = fontDescription.family();
......
......@@ -56,8 +56,8 @@ String IdentifiersFactory::requestId(unsigned long identifier)
String IdentifiersFactory::addProcessIdPrefixTo(const String& id)
{
StringBuilder builder;
builder.append(String::number(s_processId));
builder.append(".");
builder.appendNumber(s_processId);
builder.append('.');
builder.append(id);
return builder.toString();
}
......
......@@ -164,7 +164,7 @@ AtomicString FrameTree::uniqueChildName(const AtomicString& requestedName) const
}
name.appendLiteral("/<!--frame");
name.append(String::number(childCount()));
name.appendNumber(childCount());
name.appendLiteral("-->-->");
return name.toAtomicString();
......
......@@ -472,8 +472,8 @@ String SecurityOrigin::toRawString() const
result.append(m_host);
if (m_port) {
result.append(":");
result.append(String::number(m_port));
result.append(':');
result.appendNumber(m_port);
}
return result.toString();
......
......@@ -1002,7 +1002,7 @@ String Decimal::toString() const
return builder.toString();
}
builder.append("0.");
builder.appendLiteral("0.");
for (int i = adjustedExponent + 1; i < 0; ++i)
builder.append('0');
......@@ -1020,7 +1020,7 @@ String Decimal::toString() const
if (adjustedExponent) {
builder.append(adjustedExponent < 0 ? "e" : "e+");
builder.append(String::number(adjustedExponent));
builder.appendNumber(adjustedExponent);
}
}
return builder.toString();
......
......@@ -52,7 +52,7 @@ static void appendProxyServerString(StringBuilder& builder, const ProxyServer& p
builder.append(':');
ASSERT(proxyServer.port() != -1);
builder.append(String::number(proxyServer.port()));
builder.appendNumber(proxyServer.port());
}
String toString(const Vector<ProxyServer>& proxyServers)
......
......@@ -42,25 +42,37 @@ TextStream& TextStream::operator<<(bool b)
TextStream& TextStream::operator<<(int i)
{
m_text.append(String::number(i));
m_text.appendNumber(i);
return *this;
}
TextStream& TextStream::operator<<(unsigned i)
{
m_text.append(String::number(i));
m_text.appendNumber(i);
return *this;
}
TextStream& TextStream::operator<<(long i)
{
m_text.append(String::number(i));
m_text.appendNumber(i);
return *this;
}
TextStream& TextStream::operator<<(unsigned long i)
{
m_text.append(String::number(i));
m_text.appendNumber(i);
return *this;
}
TextStream& TextStream::operator<<(long long i)
{
m_text.appendNumber(i);
return *this;
}
TextStream& TextStream::operator<<(unsigned long long i)
{
m_text.appendNumber(i);
return *this;
}
......@@ -102,19 +114,4 @@ String TextStream::release()
return result;
}
#if OS(WINDOWS) && CPU(X86_64)
TextStream& TextStream::operator<<(__int64 i)
{
char buffer[printBufferSize];
snprintf(buffer, sizeof(buffer) - 1, "%I64i", i);
return *this << buffer;
}
TextStream& TextStream::operator<<(unsigned __int64 i)
{
char buffer[printBufferSize];
snprintf(buffer, sizeof(buffer) - 1, "%I64u", i);
return *this << buffer;
}
#endif
}
......@@ -39,15 +39,13 @@ public:
TextStream& operator<<(unsigned);
TextStream& operator<<(long);
TextStream& operator<<(unsigned long);
TextStream& operator<<(long long);
TextStream& operator<<(unsigned long long);
TextStream& operator<<(float);
TextStream& operator<<(double);
TextStream& operator<<(const char*);
TextStream& operator<<(const void*);
TextStream& operator<<(const String&);
#if OS(WINDOWS) && CPU(X86_64)
TextStream& operator<<(unsigned __int64);
TextStream& operator<<(__int64);
#endif
String release();
......
......@@ -809,7 +809,7 @@ static String nodePosition(Node* node)
result.append('}');
} else {
result.appendLiteral("child ");
result.append(String::number(n->nodeIndex()));
result.appendNumber(n->nodeIndex());
result.appendLiteral(" {");
result.append(getTagName(n));
result.append('}');
......
......@@ -79,11 +79,11 @@ void XMLErrors::appendErrorMessage(const String& typeString, TextPosition positi
{
// <typeString> on line <lineNumber> at column <columnNumber>: <message>
m_errorMessages.append(typeString);
m_errorMessages.append(" on line ");
m_errorMessages.append(String::number(position.m_line.oneBasedInt()));
m_errorMessages.append(" at column ");
m_errorMessages.append(String::number(position.m_column.oneBasedInt()));
m_errorMessages.append(": ");
m_errorMessages.appendLiteral(" on line ");
m_errorMessages.appendNumber(position.m_line.oneBasedInt());
m_errorMessages.appendLiteral(" at column ");
m_errorMessages.appendNumber(position.m_column.oneBasedInt());
m_errorMessages.appendLiteral(": ");
m_errorMessages.append(message);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment