Remove is_object
is_object doesn't throw, but generally is_object is used in some kind of
pattern of.
if (x.is_object()){
x["thing"];
}
operator[] technically throws if it's the wrong type, which bloats
binary sizes.
Replace these with the equivalent get_ptr<object_t>
Change-Id: If3734d7920f0a6f81efa10b3a2d91595e9e0af5a
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index f651c38..5963486 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -1321,23 +1321,27 @@
// seems better to get the data back somehow.
nlohmann::json::object_t* dataobj =
data.get_ptr<nlohmann::json::object_t*>();
- if (transaction->methodResponse.is_object() && dataobj != nullptr)
+
+ nlohmann::json::object_t* methodResponseObj =
+ transaction->methodResponse.get_ptr<nlohmann::json::object_t*>();
+ if (methodResponseObj != nullptr && dataobj != nullptr)
{
for (auto& obj : *dataobj)
{
// Note: Will overwrite the data for a duplicate key
- transaction->methodResponse.emplace(obj.first,
- std::move(obj.second));
+ methodResponseObj->emplace(obj.first, std::move(obj.second));
}
return;
}
nlohmann::json::array_t* dataarr = data.get_ptr<nlohmann::json::array_t*>();
- if (transaction->methodResponse.is_array() && dataarr != nullptr)
+ nlohmann::json::array_t* methodResponseArr =
+ transaction->methodResponse.get_ptr<nlohmann::json::array_t*>();
+ if (methodResponseArr != nullptr && dataarr != nullptr)
{
for (auto& obj : *dataarr)
{
- transaction->methodResponse.emplace_back(std::move(obj));
+ methodResponseArr->emplace_back(std::move(obj));
}
return;
}