task payload, initialize jsonValue in constructor
We should do this because it means that variables are only initialized
once. In the simplest case:
struct MyClass{
std::string myString
MyClass(){
myString = "foo";
}
}
in the language, myString is constructed twice, once with empty string,
then a second time with "foo". If you do the construction in the
initializer list for the class the construction only happens once.
Now, the above case is contrived, the optimizer can see through it and
likely optimizes this case because std::string is relatively simple, but
for more complex structures, it's possible this generates less and
bettercompiled code, and this is worth having the check for, and making
our existing code correct.
Tested: cppcheck passing.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ie5c7f293598408d437e7bf7b3fc93b0819e25f9f
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index be48a5b..08573d5 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -41,8 +41,8 @@
{
explicit Payload(const crow::Request& req) :
targetUri(req.url), httpOperation(req.methodString()),
- httpHeaders(nlohmann::json::array())
-
+ httpHeaders(nlohmann::json::array()),
+ jsonBody(nlohmann::json::parse(req.body, nullptr, false))
{
using field_ns = boost::beast::http::field;
constexpr const std::array<boost::beast::http::field, 7>
@@ -51,7 +51,6 @@
field_ns::connection, field_ns::content_length,
field_ns::upgrade};
- jsonBody = nlohmann::json::parse(req.body, nullptr, false);
if (jsonBody.is_discarded())
{
jsonBody = nullptr;