Remove nlohmann brace initialization
There's a few last places (outside of tests) where we still use
nlohmann brace initialization. Per the transforms we've been doing,
move these to constructing the objects explicitly, using operator[],
nlohmann::object_t and nlohmann::array_t. Theses were found by manual
inspection grepping for all uses of nlohmann::json.
This is done to reduce binary size and reduce the number of intermediate
objects being constructed. This commit saves a trivial amount of size
(~4KB, Half a percent of total) and in addition but makes our
construction consistent.
Tested:
Redfish service validator passes.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7478479a9fdc41b254eef325002d413c1fb411a0
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index faa295a..1b52d00 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -972,9 +972,12 @@
{
nlohmann::json& logServiceArrayLocal =
asyncResp->res.jsonValue["Members"];
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Systems/system/LogServices/PostCodes"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Systems/system/LogServices/PostCodes";
+
+ logServiceArrayLocal.push_back(std::move(member));
+
asyncResp->res.jsonValue["Members@odata.count"] =
logServiceArrayLocal.size();
return;
@@ -2013,8 +2016,9 @@
logServiceArray = nlohmann::json::array();
#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
- logServiceArray.push_back(
- {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
+ nlohmann::json::object_t journal;
+ journal["@odata.id"] = "/redfish/v1/Managers/bmc/LogServices/Journal";
+ logServiceArray.push_back(std::move(journal));
#endif
asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
@@ -2041,15 +2045,17 @@
{
if (path == "/xyz/openbmc_project/dump/bmc")
{
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Managers/bmc/LogServices/Dump"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Managers/bmc/LogServices/Dump";
+ logServiceArrayLocal.push_back(std::move(member));
}
else if (path == "/xyz/openbmc_project/dump/faultlog")
{
- logServiceArrayLocal.push_back(
- {{"@odata.id",
- "/redfish/v1/Managers/bmc/LogServices/FaultLog"}});
+ nlohmann::json::object_t member;
+ member["@odata.id"] =
+ "/redfish/v1/Managers/bmc/LogServices/FaultLog";
+ logServiceArrayLocal.push_back(std::move(member));
}
}