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/account_service.hpp b/redfish-core/lib/account_service.hpp
index 5d8bb15..91bd024 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -182,10 +182,18 @@
{
BMCWEB_LOG_DEBUG << "Pushing the data groupName="
<< obj.second.groupName << "\n";
- roleMapArray.push_back(
- {nlohmann::json::array({"RemoteGroup", obj.second.groupName}),
- nlohmann::json::array(
- {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})});
+
+ nlohmann::json::array_t remoteGroupArray;
+ nlohmann::json::object_t remoteGroup;
+ remoteGroup["RemoteGroup"] = obj.second.groupName;
+ remoteGroupArray.emplace_back(std::move(remoteGroup));
+ roleMapArray.emplace_back(std::move(remoteGroupArray));
+
+ nlohmann::json::array_t localRoleArray;
+ nlohmann::json::object_t localRole;
+ localRole["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege);
+ localRoleArray.emplace_back(std::move(localRole));
+ roleMapArray.emplace_back(std::move(localRoleArray));
}
}
@@ -1733,7 +1741,8 @@
asyncResp->res.jsonValue["Name"] = "User Account";
asyncResp->res.jsonValue["Description"] = "User Account";
asyncResp->res.jsonValue["Password"] = nullptr;
- asyncResp->res.jsonValue["AccountTypes"] = {"Redfish"};
+ asyncResp->res.jsonValue["AccountTypes"] =
+ nlohmann::json::array_t({"Redfish"});
for (const auto& interface : userIt->second)
{