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/login_routes.hpp b/include/login_routes.hpp
index 864ca00..4b4a621 100644
--- a/include/login_routes.hpp
+++ b/include/login_routes.hpp
@@ -97,20 +97,27 @@
}
}
}
- else if (dataIt->is_object())
+ else
{
- nlohmann::json::iterator userIt2 = dataIt->find("username");
- nlohmann::json::iterator passIt2 = dataIt->find("password");
- if (userIt2 != dataIt->end() && passIt2 != dataIt->end())
+ nlohmann::json::object_t* obj =
+ dataIt->get_ptr<nlohmann::json::object_t*>();
+ if (obj != nullptr)
{
- const std::string* userStr =
- userIt2->get_ptr<const std::string*>();
- const std::string* passStr =
- passIt2->get_ptr<const std::string*>();
- if (userStr != nullptr && passStr != nullptr)
+ nlohmann::json::object_t::iterator userIt2 =
+ obj->find("username");
+ nlohmann::json::object_t::iterator passIt2 =
+ obj->find("password");
+ if (userIt2 != obj->end() && passIt2 != obj->end())
{
- username = *userStr;
- password = *passStr;
+ const std::string* userStr =
+ userIt2->second.get_ptr<const std::string*>();
+ const std::string* passStr =
+ passIt2->second.get_ptr<const std::string*>();
+ if (userStr != nullptr && passStr != nullptr)
+ {
+ username = *userStr;
+ password = *passStr;
+ }
}
}
}
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;
}