Improve string efficiency using StringBuilder and StringOperations
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2012 11:16:48 +0000 (11:16 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2012 11:16:48 +0000 (11:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95304

Reviewed by Eric Seidel.

As recommended by http://trac.webkit.org/wiki/EfficientStrings.

* css/CSSLineBoxContainValue.cpp:
(WebCore::CSSLineBoxContainValue::customCssText):
* css/CSSPropertySourceData.cpp:
(WebCore::CSSPropertySourceData::toString):
* css/MediaList.cpp:
(WebCore::MediaQuerySet::mediaText):
* css/ShadowValue.cpp:
(WebCore::ShadowValue::customCssText):
* dom/MicroDataItemList.cpp:
(WebCore::MicroDataItemList::undefinedItemType):
* editing/HTMLInterchange.cpp:
(WebCore::convertedSpaceString):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSLineBoxContainValue.cpp
Source/WebCore/css/CSSPropertySourceData.cpp
Source/WebCore/css/MediaList.cpp
Source/WebCore/css/ShadowValue.cpp
Source/WebCore/dom/MicroDataItemList.cpp
Source/WebCore/editing/HTMLInterchange.cpp

index 1436d3b..1fcf10d 100644 (file)
@@ -1,3 +1,25 @@
+2012-08-29  Adam Barth  <abarth@webkit.org>
+
+        Improve string efficiency using StringBuilder and StringOperations
+        https://bugs.webkit.org/show_bug.cgi?id=95304
+
+        Reviewed by Eric Seidel.
+
+        As recommended by http://trac.webkit.org/wiki/EfficientStrings.
+
+        * css/CSSLineBoxContainValue.cpp:
+        (WebCore::CSSLineBoxContainValue::customCssText):
+        * css/CSSPropertySourceData.cpp:
+        (WebCore::CSSPropertySourceData::toString):
+        * css/MediaList.cpp:
+        (WebCore::MediaQuerySet::mediaText):
+        * css/ShadowValue.cpp:
+        (WebCore::ShadowValue::customCssText):
+        * dom/MicroDataItemList.cpp:
+        (WebCore::MicroDataItemList::undefinedItemType):
+        * editing/HTMLInterchange.cpp:
+        (WebCore::convertedSpaceString):
+
 2012-08-29  James Robinson  <jamesr@chromium.org>
 
         [chromium] Use floating point literals in expressions that initialize floats
index 85f385d..f9e3db5 100644 (file)
@@ -29,6 +29,7 @@
 #include "CSSPrimitiveValue.h"
 #include "MemoryInstrumentation.h"
 #include "PlatformString.h"
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -40,37 +41,37 @@ CSSLineBoxContainValue::CSSLineBoxContainValue(unsigned value)
 
 String CSSLineBoxContainValue::customCssText() const
 {
-    String text("");
+    StringBuilder text;
 
     if (m_value & LineBoxContainBlock)
-        text += "block";
+        text.appendLiteral("block");
     if (m_value & LineBoxContainInline) {
         if (!text.isEmpty())
-            text += " ";
-        text += "inline";
+            text.append(' ');
+        text.appendLiteral("inline");
     }
     if (m_value & LineBoxContainFont) {
         if (!text.isEmpty())
-            text += " ";
-        text += "font";
+            text.append(' ');
+        text.appendLiteral("font");
     }
     if (m_value & LineBoxContainGlyphs) {
         if (!text.isEmpty())
-            text += " ";
-        text += "glyphs";
+            text.append(' ');
+        text.appendLiteral("glyphs");
     }
     if (m_value & LineBoxContainReplaced) {
         if (!text.isEmpty())
-            text += " ";
-        text += "replaced";
+            text.append(' ');
+        text.appendLiteral("replaced");
     }
     if (m_value & LineBoxContainInlineBox) {
         if (!text.isEmpty())
-            text += " ";
-        text += "inline-box";
+            text.append(' ');
+        text.appendLiteral("inline-box");
     }
 
-    return text;
+    return text.toString();
 }
 
 void CSSLineBoxContainValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
index 96fa121..921b662 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "PlatformString.h"
 #include <wtf/StaticConstructors.h>
+#include <wtf/text/StringBuilder.h>
 #include <wtf/text/StringHash.h>
 
 namespace WebCore {
@@ -93,13 +94,14 @@ String CSSPropertySourceData::toString() const
     if (!name && value == emptyValue)
         return String();
 
-    String result = name;
-    result += ": ";
-    result += value;
+    StringBuilder result;
+    result.append(name);
+    result.appendLiteral(": ");
+    result.append(value);
     if (important)
-        result += importantSuffix;
-    result += ";";
-    return result;
+        result.append(importantSuffix);
+    result.append(';');
+    return result.toString();
 }
 
 unsigned CSSPropertySourceData::hash() const
index 5ba7341..67a6d5e 100644 (file)
@@ -27,6 +27,7 @@
 #include "MediaQuery.h"
 #include "MediaQueryExp.h"
 #include "MemoryInstrumentation.h"
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -198,17 +199,17 @@ void MediaQuerySet::addMediaQuery(PassOwnPtr<MediaQuery> mediaQuery)
 
 String MediaQuerySet::mediaText() const
 {
-    String text("");
+    StringBuilder text;
     
     bool first = true;
     for (size_t i = 0; i < m_queries.size(); ++i) {
         if (!first)
-            text += ", ";
+            text.appendLiteral(", ");
         else
             first = false;
-        text += m_queries[i]->cssText();
+        text.append(m_queries[i]->cssText());
     }
-    return text;
+    return text.toString();
 }
 
 void MediaQuerySet::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
index 5db0036..311e9b1 100644 (file)
@@ -23,6 +23,7 @@
 #include "CSSPrimitiveValue.h"
 #include "MemoryInstrumentation.h"
 #include "PlatformString.h"
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -45,37 +46,37 @@ ShadowValue::ShadowValue(PassRefPtr<CSSPrimitiveValue> _x,
 
 String ShadowValue::customCssText() const
 {
-    String text("");
+    StringBuilder text;
 
     if (color)
-        text += color->cssText();
+        text.append(color->cssText());
     if (x) {
         if (!text.isEmpty())
-            text += " ";
-        text += x->cssText();
+            text.append(' ');
+        text.append(x->cssText());
     }
     if (y) {
         if (!text.isEmpty())
-            text += " ";
-        text += y->cssText();
+            text.append(' ');
+        text.append(y->cssText());
     }
     if (blur) {
         if (!text.isEmpty())
-            text += " ";
-        text += blur->cssText();
+            text.append(' ');
+        text.append(blur->cssText());
     }
     if (spread) {
         if (!text.isEmpty())
-            text += " ";
-        text += spread->cssText();
+            text.append(' ');
+        text.append(spread->cssText());
     }
     if (style) {
         if (!text.isEmpty())
-            text += " ";
-        text += style->cssText();
+            text.append(' ');
+        text.append(style->cssText());
     }
 
-    return text;
+    return text.toString();
 }
 
 void ShadowValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
index 534c0d0..91ab982 100644 (file)
@@ -40,9 +40,7 @@ using namespace HTMLNames;
 
 const String& MicroDataItemList::undefinedItemType()
 {
-    DEFINE_STATIC_LOCAL(String, undefinedItemTypeString, (""));
-    // FIXME: Why not just return emptyString(); ?
-    return undefinedItemTypeString;
+    return emptyString();
 }
 
 MicroDataItemList::MicroDataItemList(PassRefPtr<Node> rootNode, const String& typeNames)
index b92472f..fdefa43 100644 (file)
 
 namespace WebCore {
 
-namespace {
-
-String convertedSpaceString()
+static String convertedSpaceString()
 {
-    DEFINE_STATIC_LOCAL(String, convertedSpaceString, ());
-    if (convertedSpaceString.isNull()) {
-        convertedSpaceString = "<span class=\"";
-        convertedSpaceString += AppleConvertedSpace;
-        convertedSpaceString += "\">";
-        convertedSpaceString.append(noBreakSpace);
-        convertedSpaceString += "</span>";
-    }
+    DEFINE_STATIC_LOCAL(String, convertedSpaceString, (String(ASCIILiteral("<span class=\"" AppleConvertedSpace "\">")) + noBreakSpace + "</span>"));
     return convertedSpaceString;
 }
 
-} // end anonymous namespace
-
 String convertHTMLTextToInterchangeFormat(const String& in, const Text* node)
 {
     // Assume all the text comes from node.