🐎 reduces json parsing to 0ns

json parsing used to be 75% of functions like GetBal's cost, but now its 0% as its just moved in and implicitly cast to Json::Value
This commit is contained in:
William Katz 2021-06-18 12:21:37 -07:00 committed by GitHub
parent 9f58dda6d2
commit 04bf0c55e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,35 +1,12 @@
#include "bank_f.h"
#define JSON(V) callback(HttpResponse::newHttpJsonResponse(JsonReturn(V)));
#define JSON(V) callback(HttpResponse::newHttpJsonResponse(V));
#define INLINE __attribute__((always_inline)) inline
#define GEN_BODY \
const auto temp_req = req->getJsonObject(); \
const auto body = temp_req ? *temp_req : Json::Value();
#define PASS_HEADER req->getHeader("Password")
template <typename T>
INLINE Json::Value JsonReturn(T &&val)
{
Json::Value res;
if constexpr (std::is_same_v<T, int_fast8_t>)
{
res["value"] = (int)val; //becuase of json lib interpreting 67 as 'A' for example
}
else if constexpr (std::is_same_v<T, uint64_t>)
{
res["value"] = (Json::Int64)val;
}
else if constexpr (std::is_same_v<T, int64_t>)
{
res["value"] = (Json::Int64)val;
}
else
{
res["value"] = val;
}
return res;
}
BankF::BankF(Bank *b) : bank(*b) {}
void BankF::Help(req_args) const
@ -118,4 +95,4 @@ void BankF::GetLog(req_args, const std::string &name)
resp->setExpiredTime(0); //cached forever
callback(resp);
}
}
}