Avoid temporary String objects in PerfdataValue::Format.

Fixes #5248
This commit is contained in:
Gunnar Beutner 2013-12-02 12:55:35 +01:00
parent 2a761fb285
commit 52d2066995

View File

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