Title: [127706] trunk/Source/WebCore
Revision
127706
Author
aba...@webkit.org
Date
2012-09-06 00:47:08 -0700 (Thu, 06 Sep 2012)

Log Message

More fixes for String::operator+=() in Debug mode
https://bugs.webkit.org/show_bug.cgi?id=95888

Patch by Patrick Gansterer <par...@webkit.org> on 2012-09-06
Reviewed by Adam Barth.

Use StringBuilder to concatenate strings instead of operator+=().

* dom/Element.cpp:
(WebCore::Element::formatForDebugger):
* dom/Node.cpp:
(WebCore::appendAttributeDesc):
(WebCore::Node::showNode):
(WebCore::traverseTreeAndMark):
(WebCore::Node::formatForDebugger):
* dom/Position.cpp:
(WebCore::Position::formatForDebugger):
* dom/Range.cpp:
(WebCore):
(WebCore::Range::formatForDebugger):
* dom/Text.cpp:
(WebCore::Text::formatForDebugger):
* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::formatForDebugger):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127705 => 127706)


--- trunk/Source/WebCore/ChangeLog	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/ChangeLog	2012-09-06 07:47:08 UTC (rev 127706)
@@ -1,3 +1,29 @@
+2012-09-06  Patrick Gansterer  <par...@webkit.org>
+
+        More fixes for String::operator+=() in Debug mode
+        https://bugs.webkit.org/show_bug.cgi?id=95888
+
+        Reviewed by Adam Barth.
+
+        Use StringBuilder to concatenate strings instead of operator+=().
+
+        * dom/Element.cpp:
+        (WebCore::Element::formatForDebugger):
+        * dom/Node.cpp:
+        (WebCore::appendAttributeDesc):
+        (WebCore::Node::showNode):
+        (WebCore::traverseTreeAndMark):
+        (WebCore::Node::formatForDebugger):
+        * dom/Position.cpp:
+        (WebCore::Position::formatForDebugger):
+        * dom/Range.cpp:
+        (WebCore):
+        (WebCore::Range::formatForDebugger):
+        * dom/Text.cpp:
+        (WebCore::Text::formatForDebugger):
+        * editing/VisibleSelection.cpp:
+        (WebCore::VisibleSelection::formatForDebugger):
+
 2012-09-04  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Fix inconsistencies in NetworkUISourceCodeProvider implementation.

Modified: trunk/Source/WebCore/dom/Element.cpp (127705 => 127706)


--- trunk/Source/WebCore/dom/Element.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -1397,31 +1397,28 @@
 #ifndef NDEBUG
 void Element::formatForDebugger(char* buffer, unsigned length) const
 {
-    String result;
+    StringBuilder result;
     String s;
-    
-    s = nodeName();
-    if (s.length() > 0) {
-        result += s;
-    }
-          
+
+    result.append(nodeName());
+
     s = getIdAttribute();
     if (s.length() > 0) {
         if (result.length() > 0)
-            result += "; ";
-        result += "id=";
-        result += s;
+            result.appendLiteral("; ");
+        result.appendLiteral("id=");
+        result.append(s);
     }
-          
+
     s = getAttribute(classAttr);
     if (s.length() > 0) {
         if (result.length() > 0)
-            result += "; ";
-        result += "class=";
-        result += s;
+            result.appendLiteral("; ");
+        result.appendLiteral("class=");
+        result.append(s);
     }
-          
-    strncpy(buffer, result.utf8().data(), length - 1);
+
+    strncpy(buffer, result.toString().utf8().data(), length - 1);
 }
 #endif
 

Modified: trunk/Source/WebCore/dom/Node.cpp (127705 => 127706)


--- trunk/Source/WebCore/dom/Node.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -2097,15 +2097,17 @@
 
 #ifndef NDEBUG
 
-static void appendAttributeDesc(const Node* node, String& string, const QualifiedName& name, const char* attrDesc)
+static void appendAttributeDesc(const Node* node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
 {
-    if (node->isElementNode()) {
-        String attr = static_cast<const Element*>(node)->getAttribute(name);
-        if (!attr.isEmpty()) {
-            string += attrDesc;
-            string += attr;
-        }
-    }
+    if (!node->isElementNode())
+        return;
+
+    String attr = static_cast<const Element*>(node)->getAttribute(name);
+    if (attr.isEmpty())
+        return;
+
+    stringBuilder.append(attrDesc);
+    stringBuilder.append(attr);
 }
 
 void Node::showNode(const char* prefix) const
@@ -2118,10 +2120,10 @@
         value.replace('\n', "\\n");
         fprintf(stderr, "%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), this, value.utf8().data());
     } else {
-        String attrs = "";
+        StringBuilder attrs;
         appendAttributeDesc(this, attrs, classAttr, " CLASS=");
         appendAttributeDesc(this, attrs, styleAttr, " STYLE=");
-        fprintf(stderr, "%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, attrs.utf8().data());
+        fprintf(stderr, "%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, attrs.toString().utf8().data());
     }
 }
 
@@ -2189,16 +2191,18 @@
         if (node == markedNode2)
             fprintf(stderr, "%s", markedLabel2);
 
-        String indent = baseIndent;
+        StringBuilder indent;
+        indent.append(baseIndent);
         for (const Node* tmpNode = node; tmpNode && tmpNode != rootNode; tmpNode = tmpNode->parentOrHostNode())
-            indent += "\t";
-        fprintf(stderr, "%s", indent.utf8().data());
+            indent.append('\t');
+        fprintf(stderr, "%s", indent.toString().utf8().data());
         node->showNode();
+        indent.append('\t');
         if (node->isShadowRoot()) {
             if (ShadowRoot* youngerShadowRoot = toShadowRoot(node)->youngerShadowRoot())
-                traverseTreeAndMark(indent + "\t", youngerShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
+                traverseTreeAndMark(indent.toString(), youngerShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
         } else if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(node))
-            traverseTreeAndMark(indent + "\t", oldestShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
+            traverseTreeAndMark(indent.toString(), oldestShadowRoot, markedNode1, markedLabel1, markedNode2, markedLabel2);
     }
 }
 
@@ -2218,13 +2222,13 @@
 {
     String result;
     String s;
-    
+
     s = nodeName();
-    if (s.length() == 0)
-        result += "<none>";
+    if (s.isEmpty())
+        result = "<none>";
     else
-        result += s;
-          
+        result = s;
+
     strncpy(buffer, result.utf8().data(), length - 1);
 }
 

Modified: trunk/Source/WebCore/dom/Position.cpp (127705 => 127706)


--- trunk/Source/WebCore/dom/Position.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/dom/Position.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -1314,20 +1314,20 @@
 
 void Position::formatForDebugger(char* buffer, unsigned length) const
 {
-    String result;
-    
+    StringBuilder result;
+
     if (isNull())
-        result = "<null>";
+        result.appendLiteral("<null>");
     else {
         char s[1024];
-        result += "offset ";
-        result += String::number(m_offset);
-        result += " of ";
+        result.appendLiteral("offset ");
+        result.append(String::number(m_offset));
+        result.appendLiteral(" of ");
         deprecatedNode()->formatForDebugger(s, sizeof(s));
-        result += s;
+        result.append(s);
     }
-          
-    strncpy(buffer, result.utf8().data(), length - 1);
+
+    strncpy(buffer, result.toString().utf8().data(), length - 1);
 }
 
 void Position::showAnchorTypeAndOffset() const

Modified: trunk/Source/WebCore/dom/Range.cpp (127705 => 127706)


--- trunk/Source/WebCore/dom/Range.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/dom/Range.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -1652,31 +1652,30 @@
 }
 
 #ifndef NDEBUG
-#define FormatBufferSize 1024
 void Range::formatForDebugger(char* buffer, unsigned length) const
 {
-    String result;
+    StringBuilder result;
     String s;
-    
+
     if (!m_start.container() || !m_end.container())
-        result = "<empty>";
+        result.appendLiteral("<empty>");
     else {
+        const int FormatBufferSize = 1024;
         char s[FormatBufferSize];
-        result += "from offset ";
-        result += String::number(m_start.offset());
-        result += " of ";
+        result.appendLiteral("from offset ");
+        result.append(String::number(m_start.offset()));
+        result.appendLiteral(" of ");
         m_start.container()->formatForDebugger(s, FormatBufferSize);
-        result += s;
-        result += " to offset ";
-        result += String::number(m_end.offset());
-        result += " of ";
+        result.append(s);
+        result.appendLiteral(" to offset ");
+        result.append(String::number(m_end.offset()));
+        result.appendLiteral(" of ");
         m_end.container()->formatForDebugger(s, FormatBufferSize);
-        result += s;
+        result.append(s);
     }
-          
-    strncpy(buffer, result.utf8().data(), length - 1);
+
+    strncpy(buffer, result.toString().utf8().data(), length - 1);
 }
-#undef FormatBufferSize
 #endif
 
 bool areRangesEqual(const Range* a, const Range* b)

Modified: trunk/Source/WebCore/dom/Text.cpp (127705 => 127706)


--- trunk/Source/WebCore/dom/Text.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/dom/Text.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -301,23 +301,20 @@
 #ifndef NDEBUG
 void Text::formatForDebugger(char *buffer, unsigned length) const
 {
-    String result;
+    StringBuilder result;
     String s;
-    
-    s = nodeName();
-    if (s.length() > 0) {
-        result += s;
-    }
-          
+
+    result.append(nodeName());
+
     s = data();
     if (s.length() > 0) {
-        if (result.length() > 0)
-            result += "; ";
-        result += "value=";
-        result += s;
+        if (result.length())
+            result.appendLiteral("; ");
+        result.appendLiteral("value=");
+        result.append(s);
     }
-          
-    strncpy(buffer, result.utf8().data(), length - 1);
+
+    strncpy(buffer, result.toString().utf8().data(), length - 1);
 }
 #endif
 

Modified: trunk/Source/WebCore/editing/VisibleSelection.cpp (127705 => 127706)


--- trunk/Source/WebCore/editing/VisibleSelection.cpp	2012-09-06 07:40:56 UTC (rev 127705)
+++ trunk/Source/WebCore/editing/VisibleSelection.cpp	2012-09-06 07:47:08 UTC (rev 127706)
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <wtf/Assertions.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
 #include <wtf/unicode/CharacterNames.h>
 
 namespace WebCore {
@@ -671,23 +672,23 @@
 
 void VisibleSelection::formatForDebugger(char* buffer, unsigned length) const
 {
-    String result;
+    StringBuilder result;
     String s;
-    
+
     if (isNone()) {
-        result = "<none>";
+        result.appendLiteral("<none>");
     } else {
         const int FormatBufferSize = 1024;
         char s[FormatBufferSize];
-        result += "from ";
+        result.appendLiteral("from ");
         start().formatForDebugger(s, FormatBufferSize);
-        result += s;
-        result += " to ";
+        result.append(s);
+        result.appendLiteral(" to ");
         end().formatForDebugger(s, FormatBufferSize);
-        result += s;
+        result.append(s);
     }
 
-    strncpy(buffer, result.utf8().data(), length - 1);
+    strncpy(buffer, result.toString().utf8().data(), length - 1);
 }
 
 void VisibleSelection::showTreeForThis() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to