]> granicus.if.org Git - icinga2/commitdiff
Avoid temporary String objects in PerfdataValue::Format.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 2 Dec 2013 11:55:35 +0000 (12:55 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 2 Dec 2013 11:55:35 +0000 (12:55 +0100)
Fixes #5248

lib/icinga/perfdatavalue.cpp

index 549a7cdcb12513ad64bb357726e109ed438cdcf8..d9a7a6a67820b698ecbb593fbb2cd7e6ef0f746d 100644 (file)
@@ -112,8 +112,9 @@ String PerfdataValue::Format(const Value& perfdata)
 {
        if (perfdata.IsObjectType<PerfdataValue>()) {
                PerfdataValue::Ptr pdv = perfdata;
+               std::ostringstream result;
 
-               String output = Convert::ToString(pdv->GetValue());
+               result << pdv->GetValue();
 
                String unit;
 
@@ -126,25 +127,25 @@ String PerfdataValue::Format(const Value& perfdata)
                else if (pdv->GetUnit() == "bytes")
                        unit = "B";
 
-               output += unit;
+               result << unit;
 
                if (!pdv->GetWarn().IsEmpty()) {
-                       output += ";" + pdv->GetWarn();
+                       result << ";" << pdv->GetWarn();
 
                        if (!pdv->GetCrit().IsEmpty()) {
-                               output += ";" + pdv->GetCrit();
+                               result << ";" << pdv->GetCrit();
 
                                if (!pdv->GetMin().IsEmpty()) {
-                                       output += ";" + pdv->GetMin();
+                                       result << ";" << pdv->GetMin();
 
                                        if (!pdv->GetMax().IsEmpty()) {
-                                               output += ";" + pdv->GetMax();
+                                               result << ";" << pdv->GetMax();
                                        }
                                }
                        }
                }
 
-               return output;
+               return result.str();
        } else {
                return perfdata;
        }