Diff
Modified: trunk/Source/WebCore/ChangeLog (126983 => 126984)
--- trunk/Source/WebCore/ChangeLog 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/ChangeLog 2012-08-29 11:16:48 UTC (rev 126984)
@@ -1,3 +1,25 @@
+2012-08-29 Adam Barth <[email protected]>
+
+ 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 <[email protected]>
[chromium] Use floating point literals in expressions that initialize floats
Modified: trunk/Source/WebCore/css/CSSLineBoxContainValue.cpp (126983 => 126984)
--- trunk/Source/WebCore/css/CSSLineBoxContainValue.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/css/CSSLineBoxContainValue.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -29,6 +29,7 @@
#include "CSSPrimitiveValue.h"
#include "MemoryInstrumentation.h"
#include "PlatformString.h"
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -40,37 +41,37 @@
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
Modified: trunk/Source/WebCore/css/CSSPropertySourceData.cpp (126983 => 126984)
--- trunk/Source/WebCore/css/CSSPropertySourceData.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/css/CSSPropertySourceData.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -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 @@
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
Modified: trunk/Source/WebCore/css/MediaList.cpp (126983 => 126984)
--- trunk/Source/WebCore/css/MediaList.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/css/MediaList.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -27,6 +27,7 @@
#include "MediaQuery.h"
#include "MediaQueryExp.h"
#include "MemoryInstrumentation.h"
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -198,17 +199,17 @@
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
Modified: trunk/Source/WebCore/css/ShadowValue.cpp (126983 => 126984)
--- trunk/Source/WebCore/css/ShadowValue.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/css/ShadowValue.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -23,6 +23,7 @@
#include "CSSPrimitiveValue.h"
#include "MemoryInstrumentation.h"
#include "PlatformString.h"
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -45,37 +46,37 @@
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
Modified: trunk/Source/WebCore/dom/MicroDataItemList.cpp (126983 => 126984)
--- trunk/Source/WebCore/dom/MicroDataItemList.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/dom/MicroDataItemList.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -40,9 +40,7 @@
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)
Modified: trunk/Source/WebCore/editing/HTMLInterchange.cpp (126983 => 126984)
--- trunk/Source/WebCore/editing/HTMLInterchange.cpp 2012-08-29 11:13:03 UTC (rev 126983)
+++ trunk/Source/WebCore/editing/HTMLInterchange.cpp 2012-08-29 11:16:48 UTC (rev 126984)
@@ -35,23 +35,12 @@
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.