Bug 608914 part 2. Get rid of some temporary strings now that we can AppendFloat to an nsAString. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 30 Nov 2010 13:18:15 -0500
changeset 58482 c5136e816bde486f6693971d67bcaaec00dd967d
parent 58481 48657c9d5788fec9c62e69f77bb0050290107f61
child 58483 e02412c90d50e3b944c4214f94ff2bfe458a50fe
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs608914
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 608914 part 2. Get rid of some temporary strings now that we can AppendFloat to an nsAString. r=dbaron
content/base/src/nsAttrValue.cpp
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/svg/content/src/nsSVGNumber2.cpp
layout/style/nsCSSStyleSheet.cpp
layout/style/nsCSSValue.cpp
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -440,19 +440,18 @@ nsAttrValue::ToString(nsAString& aResult
     case eSVGValue:
     {
       GetMiscContainer()->mSVGValue->GetValueString(aResult);
       break;
     }
 #endif
     case eFloatValue:
     {
-      nsAutoString str;
-      str.AppendFloat(GetFloatValue());
-      aResult = str;
+      aResult.Truncate();
+      aResult.AppendFloat(GetFloatValue());
       break;
     }
     default:
     {
       aResult.Truncate();
       break;
     }
   }
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -943,19 +943,17 @@ nsCanvasRenderingContext2D::StyleColorTo
                                         NS_GET_B(aColor)),
                         aStr);
     } else {
         CopyUTF8toUTF16(nsPrintfCString(100, "rgba(%d, %d, %d, ",
                                         NS_GET_R(aColor),
                                         NS_GET_G(aColor),
                                         NS_GET_B(aColor)),
                         aStr);
-        nsString tmp;
-        tmp.AppendFloat(nsStyleUtil::ColorComponentToFloat(NS_GET_A(aColor)));
-        aStr.Append(tmp);
+        aStr.AppendFloat(nsStyleUtil::ColorComponentToFloat(NS_GET_A(aColor)));
         aStr.Append(')');
     }
 }
 
 void
 nsCanvasRenderingContext2D::DirtyAllStyles()
 {
     for (int i = 0; i < STYLE_MAX; i++) {
--- a/content/svg/content/src/nsSVGNumber2.cpp
+++ b/content/svg/content/src/nsSVGNumber2.cpp
@@ -117,19 +117,18 @@ nsSVGNumber2::SetBaseValueString(const n
   // nsSVGElement::ParseAttribute under nsGenericElement::SetAttr,
   // which takes care of notifying.
   return NS_OK;
 }
 
 void
 nsSVGNumber2::GetBaseValueString(nsAString & aValueAsString)
 {
-  nsAutoString s;
-  s.AppendFloat(mBaseVal);
-  aValueAsString.Assign(s);
+  aValueAsString.Truncate();
+  aValueAsString.AppendFloat(mBaseVal);
 }
 
 void
 nsSVGNumber2::SetBaseValue(float aValue,
                            nsSVGElement *aSVGElement,
                            PRBool aDoSetAttr)
 {
   mBaseVal = aValue;
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -463,20 +463,17 @@ nsMediaQuery::AppendToString(nsAString& 
                          "bad unit");
             array->Item(0).AppendToString(eCSSProperty_z_index, aString);
             aString.AppendLiteral("/");
             array->Item(1).AppendToString(eCSSProperty_z_index, aString);
           }
           break;
         case nsMediaFeature::eResolution:
           {
-            nsAutoString buffer;
-            buffer.AppendFloat(expr.mValue.GetFloatValue());
-            aString.Append(buffer);
-            buffer.Truncate();
+            aString.AppendFloat(expr.mValue.GetFloatValue());
             if (expr.mValue.GetUnit() == eCSSUnit_Inch) {
               aString.AppendLiteral("dpi");
             } else {
               NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Centimeter,
                            "bad unit");
               aString.AppendLiteral("dpcm");
             }
           }
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -764,19 +764,17 @@ nsCSSValue::AppendToString(nsCSSProperty
     aResult.AppendLiteral(")");
   }
   else if (IsCalcUnit()) {
     NS_ABORT_IF_FALSE(GetUnit() == eCSSUnit_Calc, "unexpected unit");
     CSSValueSerializeCalcOps ops(aProperty, aResult);
     css::SerializeCalc(*this, ops);
   }
   else if (eCSSUnit_Integer == unit) {
-    nsAutoString tmpStr;
-    tmpStr.AppendInt(GetIntValue(), 10);
-    aResult.Append(tmpStr);
+    aResult.AppendInt(GetIntValue(), 10);
   }
   else if (eCSSUnit_Enumerated == unit) {
     if (eCSSProperty_text_decoration == aProperty) {
       PRInt32 intValue = GetIntValue();
       if (NS_STYLE_TEXT_DECORATION_NONE == intValue) {
         AppendASCIItoUTF16(nsCSSProps::LookupPropertyValue(aProperty, intValue),
                            aResult);
       } else {
@@ -827,38 +825,35 @@ nsCSSValue::AppendToString(nsCSSProperty
   }
   else if (eCSSUnit_Color == unit) {
     nscolor color = GetColorValue();
     if (color == NS_RGBA(0, 0, 0, 0)) {
       // Use the strictest match for 'transparent' so we do correct
       // round-tripping of all other rgba() values.
       aResult.AppendLiteral("transparent");
     } else {
-      nsAutoString tmpStr;
       PRUint8 a = NS_GET_A(color);
       if (a < 255) {
-        tmpStr.AppendLiteral("rgba(");
+        aResult.AppendLiteral("rgba(");
       } else {
-        tmpStr.AppendLiteral("rgb(");
+        aResult.AppendLiteral("rgb(");
       }
 
       NS_NAMED_LITERAL_STRING(comma, ", ");
 
-      tmpStr.AppendInt(NS_GET_R(color), 10);
-      tmpStr.Append(comma);
-      tmpStr.AppendInt(NS_GET_G(color), 10);
-      tmpStr.Append(comma);
-      tmpStr.AppendInt(NS_GET_B(color), 10);
+      aResult.AppendInt(NS_GET_R(color), 10);
+      aResult.Append(comma);
+      aResult.AppendInt(NS_GET_G(color), 10);
+      aResult.Append(comma);
+      aResult.AppendInt(NS_GET_B(color), 10);
       if (a < 255) {
-        tmpStr.Append(comma);
-        tmpStr.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
+        aResult.Append(comma);
+        aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
       }
-      tmpStr.Append(PRUnichar(')'));
-
-      aResult.Append(tmpStr);
+      aResult.Append(PRUnichar(')'));
     }
   }
   else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
     aResult.Append(NS_LITERAL_STRING("url("));
     nsStyleUtil::AppendEscapedCSSString(
       nsDependentString(GetOriginalURLValue()), aResult);
     aResult.Append(NS_LITERAL_STRING(")"));
   }
@@ -866,24 +861,20 @@ nsCSSValue::AppendToString(nsCSSProperty
     aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
     nsAutoString tmpStr;
     GetStringValue(tmpStr);
     nsStyleUtil::AppendEscapedCSSIdent(
       nsDependentString(tmpStr), aResult);
     aResult.Append(NS_LITERAL_STRING(")"));
   }
   else if (eCSSUnit_Percent == unit) {
-    nsAutoString tmpStr;
-    tmpStr.AppendFloat(GetPercentValue() * 100.0f);
-    aResult.Append(tmpStr);
+    aResult.AppendFloat(GetPercentValue() * 100.0f);
   }
   else if (eCSSUnit_Percent < unit) {  // length unit
-    nsAutoString tmpStr;
-    tmpStr.AppendFloat(GetFloatValue());
-    aResult.Append(tmpStr);
+    aResult.AppendFloat(GetFloatValue());
   }
   else if (eCSSUnit_Gradient == unit) {
     nsCSSValueGradient* gradient = GetGradientValue();
 
     if (gradient->mIsRepeating) {
       if (gradient->mIsRadial)
         aResult.AppendLiteral("-moz-repeating-radial-gradient(");
       else