fix more push vs emplace calls
It seems like clang-tidy doesn't catch every place that an emplace could
be used instead of a push. Use a few grep/sed pairs to find and fix up
some common patterns.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I93eaec26b8e3be240599e92b66cf54947073dc4c
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index c2bf14a..edf64a4 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -246,8 +246,8 @@
const std::filesystem::path& pathObj = file.path();
if (std::filesystem::is_regular_file(pathObj))
{
- pathObjList.push_back("/ibm/v1/Host/ConfigFiles/" +
- pathObj.filename().string());
+ pathObjList.emplace_back("/ibm/v1/Host/ConfigFiles/" +
+ pathObj.filename().string());
}
}
}
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 82e3ecd..5125764 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -144,7 +144,7 @@
nlohmann::json::object_t object;
object["path"] = objectPath;
- transaction->res.jsonValue["objects"].push_back(std::move(object));
+ transaction->res.jsonValue["objects"].emplace_back(std::move(object));
tinyxml2::XMLDocument doc;
@@ -1356,7 +1356,7 @@
{
for (auto& obj : data)
{
- transaction->methodResponse.push_back(std::move(obj));
+ transaction->methodResponse.emplace_back(std::move(obj));
}
return;
}
@@ -1366,13 +1366,13 @@
// They are different types. May as well turn them into an array
nlohmann::json j = std::move(transaction->methodResponse);
transaction->methodResponse = nlohmann::json::array();
- transaction->methodResponse.push_back(std::move(j));
- transaction->methodResponse.push_back(std::move(data));
+ transaction->methodResponse.emplace_back(std::move(j));
+ transaction->methodResponse.emplace_back(std::move(data));
transaction->convertedToArray = true;
}
else
{
- transaction->methodResponse.push_back(std::move(data));
+ transaction->methodResponse.emplace_back(std::move(data));
}
}
@@ -2199,7 +2199,7 @@
{
nlohmann::json::object_t interfaceObj;
interfaceObj["name"] = ifaceName;
- interfacesArray.push_back(std::move(interfaceObj));
+ interfacesArray.emplace_back(std::move(interfaceObj));
}
interface = interface->NextSiblingElement("interface");
@@ -2291,7 +2291,7 @@
thisArg[fieldName] = fieldValue;
}
}
- argsArray.push_back(std::move(thisArg));
+ argsArray.emplace_back(std::move(thisArg));
arg = arg->NextSiblingElement("arg");
}
@@ -2314,7 +2314,7 @@
object["uri"] = std::move(uri);
object["args"] = argsArray;
- methodsArray.push_back(std::move(object));
+ methodsArray.emplace_back(std::move(object));
}
methods = methods->NextSiblingElement("method");
}
@@ -2344,7 +2344,7 @@
nlohmann::json::object_t object;
object["name"] = name;
object["args"] = argsArray;
- signalsArray.push_back(std::move(object));
+ signalsArray.emplace_back(std::move(object));
}
signals = signals->NextSiblingElement("signal");
@@ -2461,7 +2461,7 @@
{
nlohmann::json::object_t object;
object["name"] = name;
- objectsSub.push_back(std::move(object));
+ objectsSub.emplace_back(std::move(object));
}
}
};
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index e93d216..4344074 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -243,7 +243,7 @@
{
session["client_id"] = *p.second->clientId;
}
- sessions.push_back(std::move(session));
+ sessions.emplace_back(std::move(session));
}
}
nlohmann::json& subscriptions = data["subscriptions"];
@@ -286,7 +286,7 @@
subscription["MetricReportDefinitions"] =
subValue->metricReportDefinitions;
- subscriptions.push_back(std::move(subscription));
+ subscriptions.emplace_back(std::move(subscription));
}
persistentFile << data;
}