Use StringBuilder::appendLiteral when possible don't append result of makeString
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2016 00:33:47 +0000 (00:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Aug 2016 00:33:47 +0000 (00:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160772

Patch by Alex Christensen <achristensen@webkit.org> on 2016-08-11
Reviewed by Sam Weinig.

Source/JavaScriptCore:

* API/tests/ExecutionTimeLimitTest.cpp:
(testExecutionTimeLimit):
* API/tests/PingPongStackOverflowTest.cpp:
(PingPongStackOverflowObject_hasInstance):
* bytecompiler/NodesCodegen.cpp:
(JSC::ArrayPatternNode::toString):
(JSC::RestParameterNode::toString):
* runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::sanitizedToString):
* runtime/Options.cpp:
(JSC::Options::dumpOption):

Source/WebCore:

StringBuilder::append does an unnecessary strlen call.
append(makeString(...)) always does unnecessary allocations and copies.
It's currently only used in debug logging, but we shouldn't have this pattern in WebKit.

* Modules/indexeddb/server/IndexValueStore.cpp:
(WebCore::IDBServer::IndexValueStore::loggingString):
* Modules/indexeddb/shared/IDBDatabaseInfo.cpp:
(WebCore::IDBDatabaseInfo::loggingString):
* Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:
(WebCore::IDBObjectStoreInfo::loggingString):
* contentextensions/CombinedURLFilters.cpp:
(WebCore::ContentExtensions::prefixTreeVertexToString):
(WebCore::ContentExtensions::recursivePrint):
* html/HTMLMediaElement.cpp:
(WebCore::actionName):
* html/MediaElementSession.cpp:
(WebCore::restrictionName):
* loader/ResourceLoadStatistics.cpp:
(WebCore::appendBoolean):
(WebCore::appendHashCountedSet):
(WebCore::ResourceLoadStatistics::toString):
* platform/PODInterval.h:
(WebCore::PODInterval::toString):
* platform/URL.cpp:
(WebCore::URL::setHost):
(WebCore::URL::setHostAndPort):
(WebCore::URL::serialize):
* testing/Internals.cpp:
(WebCore::appendOffsets):
(WebCore::Internals::scrollSnapOffsets):

Source/WebKit2:

* Shared/Gamepad/GamepadData.cpp:
(WebKit::GamepadData::isNull):
(WebKit::GamepadData::loggingString):
* Shared/Gamepad/GamepadData.h:
* UIProcess/WebProcessPool.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204394 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp
Source/JavaScriptCore/API/tests/PingPongStackOverflowTest.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/runtime/ErrorInstance.cpp
Source/JavaScriptCore/runtime/Options.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IndexValueStore.cpp
Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp
Source/WebCore/Modules/indexeddb/shared/IDBObjectStoreInfo.cpp
Source/WebCore/contentextensions/CombinedURLFilters.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/MediaElementSession.cpp
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebCore/platform/PODInterval.h
Source/WebCore/platform/URL.cpp
Source/WebCore/testing/Internals.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/Gamepad/GamepadData.cpp
Source/WebKit2/Shared/Gamepad/GamepadData.h
Source/WebKit2/UIProcess/WebProcessPool.h

index fc8cc10..d5e5324 100644 (file)
@@ -142,9 +142,9 @@ int testExecutionTimeLimit()
             unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
 
             StringBuilder scriptBuilder;
-            scriptBuilder.append("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
+            scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
             scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
-            scriptBuilder.append(") break; } } foo();");
+            scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
@@ -178,16 +178,16 @@ int testExecutionTimeLimit()
             unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
 
             StringBuilder scriptBuilder;
-            scriptBuilder.append("var startTime = currentCPUTime();"
+            scriptBuilder.appendLiteral("var startTime = currentCPUTime();"
                                  "function recurse(i) {"
                                      "'use strict';"
                                      "if (i % 1000 === 0) {"
                                         "if (currentCPUTime() - startTime >");
             scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
-            scriptBuilder.append("       ) { return; }");
-            scriptBuilder.append("    }");
-            scriptBuilder.append("    return recurse(i + 1); }");
-            scriptBuilder.append("recurse(0);");
+            scriptBuilder.appendLiteral("       ) { return; }");
+            scriptBuilder.appendLiteral("    }");
+            scriptBuilder.appendLiteral("    return recurse(i + 1); }");
+            scriptBuilder.appendLiteral("recurse(0);");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
@@ -221,9 +221,9 @@ int testExecutionTimeLimit()
             unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
             
             StringBuilder scriptBuilder;
-            scriptBuilder.append("function foo() { var startTime = currentCPUTime(); try { while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
+            scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); try { while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
             scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
-            scriptBuilder.append(") break; } } catch(e) { } } foo();");
+            scriptBuilder.appendLiteral(") break; } } catch(e) { } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
@@ -258,9 +258,9 @@ int testExecutionTimeLimit()
             unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
             
             StringBuilder scriptBuilder;
-            scriptBuilder.append("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
+            scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
             scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
-            scriptBuilder.append(") break; } } foo();");
+            scriptBuilder.appendLiteral(") break; } } foo();");
             
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
@@ -295,9 +295,9 @@ int testExecutionTimeLimit()
             unsigned timeAfterWatchdogShouldHaveFired = 300 + tierAdjustmentMillis;
             
             StringBuilder scriptBuilder;
-            scriptBuilder.append("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
+            scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
             scriptBuilder.appendNumber(timeAfterWatchdogShouldHaveFired / 1000.0);
-            scriptBuilder.append(") break; } } foo();");
+            scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
@@ -332,9 +332,9 @@ int testExecutionTimeLimit()
             unsigned maxBusyLoopTime = 750 + tierAdjustmentMillis;
 
             StringBuilder scriptBuilder;
-            scriptBuilder.append("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
+            scriptBuilder.appendLiteral("function foo() { var startTime = currentCPUTime(); while (true) { for (var i = 0; i < 1000; i++); if (currentCPUTime() - startTime > ");
             scriptBuilder.appendNumber(maxBusyLoopTime / 1000.0); // in seconds.
-            scriptBuilder.append(") break; } } foo();");
+            scriptBuilder.appendLiteral(") break; } } foo();");
 
             JSStringRef script = JSStringCreateWithUTF8CString(scriptBuilder.toString().utf8().data());
             exception = nullptr;
index 1ffe757..ef4b914 100644 (file)
@@ -56,13 +56,13 @@ static bool PingPongStackOverflowObject_hasInstance(JSContextRef context, JSObje
         result = JSObjectCallAsFunction(context, function, constructor, 1, &possibleValue, exception);
     } else {
         StringBuilder builder;
-        builder.append("dummy.valueOf([0]");
+        builder.appendLiteral("dummy.valueOf([0]");
         for (int i = 1; i < 35000; i++) {
-            builder.append(", [");
+            builder.appendLiteral(", [");
             builder.appendNumber(i);
-            builder.append("]");
+            builder.appendLiteral("]");
         }
-        builder.append(");");
+        builder.appendLiteral(");");
 
         JSStringRef script = JSStringCreateWithUTF8CString(builder.toString().utf8().data());
         result = JSEvaluateScript(context, script, NULL, NULL, 1, exception);
index a040320..82dfb13 100644 (file)
@@ -1,3 +1,22 @@
+2016-08-11  Alex Christensen  <achristensen@webkit.org>
+
+        Use StringBuilder::appendLiteral when possible don't append result of makeString
+        https://bugs.webkit.org/show_bug.cgi?id=160772
+
+        Reviewed by Sam Weinig.
+
+        * API/tests/ExecutionTimeLimitTest.cpp:
+        (testExecutionTimeLimit):
+        * API/tests/PingPongStackOverflowTest.cpp:
+        (PingPongStackOverflowObject_hasInstance):
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::ArrayPatternNode::toString):
+        (JSC::RestParameterNode::toString):
+        * runtime/ErrorInstance.cpp:
+        (JSC::ErrorInstance::sanitizedToString):
+        * runtime/Options.cpp:
+        (JSC::Options::dumpOption):
+
 2016-08-11  Benjamin Poulain  <bpoulain@apple.com>
 
         [JSC] Revert most of r203808
index 180c9e9..e22c5bf 100644 (file)
@@ -3747,7 +3747,7 @@ void ArrayPatternNode::toString(StringBuilder& builder) const
             break;
 
         case BindingType::RestElement:
-            builder.append("...");
+            builder.appendLiteral("...");
             target.pattern->toString(builder);
             break;
         }
@@ -3928,7 +3928,7 @@ void RestParameterNode::collectBoundIdentifiers(Vector<Identifier>& identifiers)
 
 void RestParameterNode::toString(StringBuilder& builder) const
 {
-    builder.append("...");
+    builder.appendLiteral("...");
     m_pattern->toString(builder);
 }
 
index ebf4fea..db4f614 100644 (file)
@@ -212,7 +212,7 @@ String ErrorInstance::sanitizedToString(ExecState* exec)
 
     StringBuilder builder;
     builder.append(nameString);
-    builder.append(": ");
+    builder.appendLiteral(": ");
     builder.append(messageString);
     return builder.toString();
 }
index 85f68e9..156eb08 100644 (file)
@@ -730,13 +730,13 @@ void Options::dumpOption(StringBuilder& builder, DumpLevel level, Options::ID id
     option.dump(builder);
 
     if (wasOverridden && (dumpDefaultsOption == DumpDefaults)) {
-        builder.append(" (default: ");
+        builder.appendLiteral(" (default: ");
         option.defaultOption().dump(builder);
-        builder.append(")");
+        builder.appendLiteral(")");
     }
 
     if (needsDescription) {
-        builder.append("   ... ");
+        builder.appendLiteral("   ... ");
         builder.append(option.description());
     }
 
index de540e1..dfff309 100644 (file)
@@ -1,3 +1,41 @@
+2016-08-11  Alex Christensen  <achristensen@webkit.org>
+
+        Use StringBuilder::appendLiteral when possible don't append result of makeString
+        https://bugs.webkit.org/show_bug.cgi?id=160772
+
+        Reviewed by Sam Weinig.
+
+        StringBuilder::append does an unnecessary strlen call.
+        append(makeString(...)) always does unnecessary allocations and copies.
+        It's currently only used in debug logging, but we shouldn't have this pattern in WebKit.
+
+        * Modules/indexeddb/server/IndexValueStore.cpp:
+        (WebCore::IDBServer::IndexValueStore::loggingString):
+        * Modules/indexeddb/shared/IDBDatabaseInfo.cpp:
+        (WebCore::IDBDatabaseInfo::loggingString):
+        * Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:
+        (WebCore::IDBObjectStoreInfo::loggingString):
+        * contentextensions/CombinedURLFilters.cpp:
+        (WebCore::ContentExtensions::prefixTreeVertexToString):
+        (WebCore::ContentExtensions::recursivePrint):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::actionName):
+        * html/MediaElementSession.cpp:
+        (WebCore::restrictionName):
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::appendBoolean):
+        (WebCore::appendHashCountedSet):
+        (WebCore::ResourceLoadStatistics::toString):
+        * platform/PODInterval.h:
+        (WebCore::PODInterval::toString):
+        * platform/URL.cpp:
+        (WebCore::URL::setHost):
+        (WebCore::URL::setHostAndPort):
+        (WebCore::URL::serialize):
+        * testing/Internals.cpp:
+        (WebCore::appendOffsets):
+        (WebCore::Internals::scrollSnapOffsets):
+
 2016-08-11  Chris Dumez  <cdumez@apple.com>
 
         Align Range.surroundContents() with the latest DOM specification
index e6129f0..da3c799 100644 (file)
@@ -32,6 +32,7 @@
 #include "IDBKeyRangeData.h"
 #include "Logging.h"
 #include "MemoryIndex.h"
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 namespace IDBServer {
@@ -387,12 +388,15 @@ const IDBKeyData& IndexValueStore::Iterator::primaryKey()
 #if !LOG_DISABLED
 String IndexValueStore::loggingString() const
 {
-    String result;
+    StringBuilder builder;
     for (auto& key : m_orderedKeys) {
-        result.append(makeString("Key: ", key.loggingString()));
-        result.append(makeString("  Entry has ", String::number(m_records.get(key)->getCount()), " entries"));
+        builder.appendLiteral("Key: ");
+        builder.append(key.loggingString());
+        builder.appendLiteral("  Entry has ");
+        builder.appendNumber(m_records.get(key)->getCount());
+        builder.appendLiteral(" entries");
     }
-    return result;
+    return builder.toString();
 }
 #endif
 
index 799376b..d250b98 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "IDBDatabaseInfo.h"
 
+#include <wtf/text/StringBuilder.h>
+
 #if ENABLE(INDEXED_DATABASE)
 
 namespace WebCore {
@@ -147,11 +149,18 @@ void IDBDatabaseInfo::deleteObjectStore(uint64_t objectStoreIdentifier)
 #if !LOG_DISABLED
 String IDBDatabaseInfo::loggingString() const
 {
-    String top = makeString("Database: ", m_name, " version ", String::number(m_version), "\n");
-    for (auto objectStore : m_objectStoreMap.values())
-        top.append(makeString(objectStore.loggingString(1), "\n"));
+    StringBuilder builder;
+    builder.appendLiteral("Database:");
+    builder.append(m_name);
+    builder.appendLiteral(" version ");
+    builder.appendNumber(m_version);
+    builder.append('\n');
+    for (auto objectStore : m_objectStoreMap.values()) {
+        builder.append(objectStore.loggingString(1));
+        builder.append('\n');
+    }
 
-    return top; 
+    return builder.toString();
 }
 #endif
 
index 3923f1a..28928a1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "IDBObjectStoreInfo.h"
+#include <wtf/text/StringBuilder.h>
 
 #if ENABLE(INDEXED_DATABASE)
 
@@ -126,15 +127,19 @@ void IDBObjectStoreInfo::deleteIndex(uint64_t indexIdentifier)
 #if !LOG_DISABLED
 String IDBObjectStoreInfo::loggingString(int indent) const
 {
-    String indentString;
+    StringBuilder builder;
     for (int i = 0; i < indent; ++i)
-        indentString.append(" ");
-
-    String top = makeString(indentString, "Object store: ", m_name, String::format(" (%" PRIu64 ") \n", m_identifier));
-    for (auto index : m_indexMap.values())
-        top.append(makeString(index.loggingString(indent + 1), "\n"));
+        builder.append(' ');
+
+    builder.appendLiteral("Object store: ");
+    builder.append(m_name);
+    builder.appendNumber(m_identifier);
+    for (auto index : m_indexMap.values()) {
+        builder.append(index.loggingString(indent + 1));
+        builder.append('\n');
+    }
 
-    return top; 
+    return builder.toString();
 }
 #endif
 
index 5573e76..c395095 100644 (file)
@@ -96,8 +96,8 @@ static String prefixTreeVertexToString(const PrefixTreeVertex& vertex, const Has
 {
     StringBuilder builder;
     while (depth--)
-        builder.append("  ");
-    builder.append("vertex actions: ");
+        builder.appendLiteral("  ");
+    builder.appendLiteral("vertex actions: ");
 
     auto actionsSlot = actions.find(&vertex);
     if (actionsSlot != actions.end()) {
@@ -117,7 +117,7 @@ static void recursivePrint(const PrefixTreeVertex& vertex, const HashMap<const P
         StringBuilder builder;
         for (unsigned i = 0; i < depth * 2; ++i)
             builder.append(' ');
-        builder.append("vertex edge: ");
+        builder.appendLiteral("vertex edge: ");
         builder.append(edge.term->toString());
         builder.append('\n');
         dataLogF("%s", builder.toString().utf8().data());
index db6d4ee..d0f0dc9 100644 (file)
@@ -195,7 +195,7 @@ static String actionName(HTMLMediaElementEnums::DelayedActionType action)
 #define ACTION(_actionType) \
     if (action & (HTMLMediaElementEnums::_actionType)) { \
         if (!actionBuilder.isEmpty()) \
-        actionBuilder.append(", "); \
+        actionBuilder.appendLiteral(", "); \
         actionBuilder.append(#_actionType); \
     } \
 
index d44c9f4..b190096 100644 (file)
@@ -68,7 +68,7 @@ static String restrictionName(MediaElementSession::BehaviorRestrictions restrict
 #define CASE(restrictionType) \
     if (restriction & MediaElementSession::restrictionType) { \
         if (!restrictionBuilder.isEmpty()) \
-            restrictionBuilder.append(", "); \
+            restrictionBuilder.appendLiteral(", "); \
         restrictionBuilder.append(#restrictionType); \
     } \
 
index 7311423..7a14b7e 100644 (file)
@@ -176,9 +176,9 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
 
 static void appendBoolean(StringBuilder& builder, const String& label, bool flag)
 {
-    builder.append("    ");
+    builder.appendLiteral("    ");
     builder.append(label);
-    builder.append(": ");
+    builder.appendLiteral(": ");
     builder.append(flag ? "Yes" : "No");
 }
 
@@ -187,14 +187,14 @@ static void appendHashCountedSet(StringBuilder& builder, const String& label, co
     if (hashCountedSet.isEmpty())
         return;
 
-    builder.append("    ");
+    builder.appendLiteral("    ");
     builder.append(label);
-    builder.append(":\n");
+    builder.appendLiteral(":\n");
 
     for (auto& entry : hashCountedSet) {
-        builder.append("        ");
+        builder.appendLiteral("        ");
         builder.append(entry.key);
-        builder.append(": ");
+        builder.appendLiteral(": ");
         builder.appendNumber(entry.value);
         builder.append('\n');
     }
@@ -212,54 +212,54 @@ String ResourceLoadStatistics::toString() const
     // Top frame stats
     appendBoolean(builder, "topFrameHasBeenNavigatedToBefore", topFrameHasBeenNavigatedToBefore);
     builder.append('\n');
-    builder.append("    topFrameHasBeenRedirectedTo: ");
+    builder.appendLiteral("    topFrameHasBeenRedirectedTo: ");
     builder.appendNumber(topFrameHasBeenRedirectedTo);
     builder.append('\n');
-    builder.append("    topFrameHasBeenRedirectedFrom: ");
+    builder.appendLiteral("    topFrameHasBeenRedirectedFrom: ");
     builder.appendNumber(topFrameHasBeenRedirectedFrom);
     builder.append('\n');
-    builder.append("    topFrameInitialLoadCount: ");
+    builder.appendLiteral("    topFrameInitialLoadCount: ");
     builder.appendNumber(topFrameInitialLoadCount);
     builder.append('\n');
-    builder.append("    topFrameHasBeenNavigatedTo: ");
+    builder.appendLiteral("    topFrameHasBeenNavigatedTo: ");
     builder.appendNumber(topFrameHasBeenNavigatedTo);
     builder.append('\n');
-    builder.append("    topFrameHasBeenNavigatedFrom: ");
+    builder.appendLiteral("    topFrameHasBeenNavigatedFrom: ");
     builder.appendNumber(topFrameHasBeenNavigatedFrom);
     builder.append('\n');
     
     // Subframe stats
     appendBoolean(builder, "subframeHasBeenLoadedBefore", subframeHasBeenLoadedBefore);
     builder.append('\n');
-    builder.append("    subframeHasBeenRedirectedTo: ");
+    builder.appendLiteral("    subframeHasBeenRedirectedTo: ");
     builder.appendNumber(subframeHasBeenRedirectedTo);
     builder.append('\n');
-    builder.append("    subframeHasBeenRedirectedFrom: ");
+    builder.appendLiteral("    subframeHasBeenRedirectedFrom: ");
     builder.appendNumber(subframeHasBeenRedirectedFrom);
     builder.append('\n');
-    builder.append("    subframeSubResourceCount: ");
+    builder.appendLiteral("    subframeSubResourceCount: ");
     builder.appendNumber(subframeSubResourceCount);
     builder.append('\n');
     appendHashCountedSet(builder, "subframeUnderTopFrameOrigins", subframeUnderTopFrameOrigins);
     appendHashCountedSet(builder, "subframeUniqueRedirectsTo", subframeUniqueRedirectsTo);
-    builder.append("    subframeHasBeenNavigatedTo: ");
+    builder.appendLiteral("    subframeHasBeenNavigatedTo: ");
     builder.appendNumber(subframeHasBeenNavigatedTo);
     builder.append('\n');
-    builder.append("    subframeHasBeenNavigatedFrom: ");
+    builder.appendLiteral("    subframeHasBeenNavigatedFrom: ");
     builder.appendNumber(subframeHasBeenNavigatedFrom);
     builder.append('\n');
     
     // Subresource stats
-    builder.append("    subresourceHasBeenRedirectedFrom: ");
+    builder.appendLiteral("    subresourceHasBeenRedirectedFrom: ");
     builder.appendNumber(subresourceHasBeenRedirectedFrom);
     builder.append('\n');
-    builder.append("    subresourceHasBeenRedirectedTo: ");
+    builder.appendLiteral("    subresourceHasBeenRedirectedTo: ");
     builder.appendNumber(subresourceHasBeenRedirectedTo);
     builder.append('\n');
-    builder.append("    subresourceHasBeenSubresourceCount: ");
+    builder.appendLiteral("    subresourceHasBeenSubresourceCount: ");
     builder.appendNumber(subresourceHasBeenSubresourceCount);
     builder.append('\n');
-    builder.append("    subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited: ");
+    builder.appendLiteral("    subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited: ");
     builder.appendNumber(subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited);
     builder.append('\n');
     appendHashCountedSet(builder, "subresourceUnderTopFrameOrigins", subresourceUnderTopFrameOrigins);
index 08be0be..f95a338 100644 (file)
@@ -136,13 +136,13 @@ public:
     String toString() const
     {
         StringBuilder builder;
-        builder.append("[PODInterval (");
+        builder.appendLiteral("[PODInterval (");
         builder.append(ValueToString<T>::string(low()));
-        builder.append(", ");
+        builder.appendLiteral(", ");
         builder.append(ValueToString<T>::string(high()));
-        builder.append("), data=");
+        builder.appendLiteral("), data=");
         builder.append(ValueToString<UserData>::string(data()));
-        builder.append(", maxHigh=");
+        builder.appendLiteral(", maxHigh=");
         builder.append(ValueToString<T>::string(maxHigh()));
         builder.append(']');
         return builder.toString();
index f5a9044..0060569 100644 (file)
@@ -896,7 +896,7 @@ void URL::setHost(const String& s)
     StringBuilder builder;
     builder.append(m_string.left(hostStart()));
     if (slashSlashNeeded)
-        builder.append("//");
+        builder.appendLiteral("//");
     builder.append(StringView(encodedHostName.data(), encodedHostName.size()));
     builder.append(m_string.substring(m_hostEnd));
     
@@ -951,10 +951,10 @@ void URL::setHostAndPort(const String& hostAndPort)
     StringBuilder builder;
     builder.append(m_string.left(hostStart()));
     if (slashSlashNeeded)
-        builder.append("//");
+        builder.appendLiteral("//");
     builder.append(StringView(encodedHostName.data(), encodedHostName.size()));
     if (!port.isEmpty()) {
-        builder.append(":");
+        builder.appendLiteral(":");
         builder.append(port);
     }
     builder.append(m_string.substring(m_portEnd));
@@ -1212,42 +1212,42 @@ String URL::serialize(bool omitFragment) const
 
     StringBuilder urlBuilder;
     urlBuilder.append(m_string, 0, m_schemeEnd);
-    urlBuilder.append(":");
+    urlBuilder.appendLiteral(":");
     unsigned start = hostStart();
     if (start < m_hostEnd) {
-        urlBuilder.append("//");
+        urlBuilder.appendLiteral("//");
         if (hasUsername()) {
             urlBuilder.append(m_string, m_userStart, m_userEnd - m_userStart);
             unsigned passwordStart = m_userEnd + 1;
             if (hasPassword()) {
-                urlBuilder.append(":");
+                urlBuilder.appendLiteral(":");
                 urlBuilder.append(m_string, passwordStart, m_passwordEnd - passwordStart);
             }
-            urlBuilder.append("@");
+            urlBuilder.appendLiteral("@");
         }
         // FIXME: Serialize host according https://url.spec.whatwg.org/#concept-host-serializer for IPv4 and IPv6 addresses.
         urlBuilder.append(m_string, start, m_hostEnd - start);
         if (hasPort()) {
-            urlBuilder.append(":");
+            urlBuilder.appendLiteral(":");
             urlBuilder.appendNumber(port());
         }
     } else if (protocolIs("file"))
-        urlBuilder.append("//");
+        urlBuilder.appendLiteral("//");
     if (cannotBeABaseURL(*this))
         urlBuilder.append(m_string, m_portEnd, m_pathEnd - m_portEnd);
     else {
-        urlBuilder.append("/");
+        urlBuilder.appendLiteral("/");
         if (m_pathEnd > m_portEnd) {
             unsigned pathStart = m_portEnd + 1;
             urlBuilder.append(m_string, pathStart, m_pathEnd - pathStart);
         }
     }
     if (hasQuery()) {
-        urlBuilder.append("?");
+        urlBuilder.appendLiteral("?");
         urlBuilder.append(m_string, m_pathEnd + 1, m_queryEnd - (m_pathEnd + 1));
     }
     if (!omitFragment && hasFragment()) {
-        urlBuilder.append("#");
+        urlBuilder.appendLiteral("#");
         urlBuilder.append(m_string, m_queryEnd + 1, m_fragmentEnd - (m_queryEnd + 1));
     }
     return urlBuilder.toString();
index ddd4f2a..9d7568f 100644 (file)
@@ -3130,16 +3130,16 @@ static void appendOffsets(StringBuilder& builder, const Vector<LayoutUnit>& snap
 {
     bool justStarting = true;
 
-    builder.append("{ ");
+    builder.appendLiteral("{ ");
     for (auto& coordinate : snapOffsets) {
         if (!justStarting)
-            builder.append(", ");
+            builder.appendLiteral(", ");
         else
             justStarting = false;
         
         builder.append(String::number(coordinate.toUnsigned()));
     }
-    builder.append(" }");
+    builder.appendLiteral(" }");
 }
     
 String Internals::scrollSnapOffsets(Element& element, ExceptionCode& ec)
index 990f30a..130aa63 100644 (file)
@@ -1,3 +1,16 @@
+2016-08-11  Alex Christensen  <achristensen@webkit.org>
+
+        Use StringBuilder::appendLiteral when possible don't append result of makeString
+        https://bugs.webkit.org/show_bug.cgi?id=160772
+
+        Reviewed by Sam Weinig.
+
+        * Shared/Gamepad/GamepadData.cpp:
+        (WebKit::GamepadData::isNull):
+        (WebKit::GamepadData::loggingString):
+        * Shared/Gamepad/GamepadData.h:
+        * UIProcess/WebProcessPool.h:
+
 2016-08-10  Alex Christensen  <achristensen@webkit.org>
 
         Fix crash when changing cookie accept policy after r204327
index 794d888..a1b2b4c 100644 (file)
@@ -57,21 +57,34 @@ bool GamepadData::isNull() const
     return !index && axisValues.isEmpty() && buttonValues.isEmpty();
 }
 
+#if !LOG_DISABLED
 String GamepadData::loggingString() const
 {
     StringBuilder builder;
 
-    builder.append(makeString(String::number(axisValues.size()), " axes, ", String::number(buttonValues.size()), " buttons\n"));
-
-    for (size_t i = 0; i < axisValues.size(); ++i)
-        builder.append(makeString(" Axis ", String::number(i), ": ", String::number(axisValues[i])));
-
-    builder.append("\n");
-    for (size_t i = 0; i < buttonValues.size(); ++i)
-        builder.append(makeString(" Button ", String::number(i), ": ", String::number(buttonValues[i])));
+    builder.appendNumber(axisValues.size());
+    builder.appendLiteral(" axes, ");
+    builder.appendNumber(buttonValues.size());
+    builder.appendLiteral(" buttons\n");
+
+    for (size_t i = 0; i < axisValues.size(); ++i) {
+        builder.appendLiteral(" Axis ");
+        builder.appendNumber(i);
+        builder.appendLiteral(": ");
+        builder.appendNumber(axisValues[i]);
+    }
+
+    builder.append('\n');
+    for (size_t i = 0; i < buttonValues.size(); ++i) {
+        builder.appendLiteral(" Button ");
+        builder.appendNumber(i);
+        builder.appendLiteral(": ");
+        builder.appendNumber(buttonValues[i]);
+    }
 
     return builder.toString();
 }
+#endif
 
 } // namespace WebKit
 
index 90b303b..c6aba16 100644 (file)
@@ -47,7 +47,9 @@ struct GamepadData {
     Vector<double> axisValues;
     Vector<double> buttonValues;
 
+#if !LOG_DISABLED
     String loggingString() const;
+#endif
 };
 
 } // namespace WebKit
index 91025ab..6b09b00 100644 (file)
@@ -85,7 +85,6 @@ class WebContextSupplement;
 class WebIconDatabase;
 class WebPageGroup;
 class WebPageProxy;
-struct GamepadData;
 struct NetworkProcessCreationParameters;
 struct StatisticsData;
 struct WebProcessCreationParameters;