From 04bf0c55e41a81a32f76839d3d33abe60bfe5aa9 Mon Sep 17 00:00:00 2001 From: William Katz Date: Fri, 18 Jun 2021 12:21:37 -0700 Subject: [PATCH] :racehorse: 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 --- src/bank_f.cpp | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/bank_f.cpp b/src/bank_f.cpp index de8cb40..c62b1d9 100644 --- a/src/bank_f.cpp +++ b/src/bank_f.cpp @@ -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 -INLINE Json::Value JsonReturn(T &&val) -{ - Json::Value res; - if constexpr (std::is_same_v) - { - res["value"] = (int)val; //becuase of json lib interpreting 67 as 'A' for example - } - else if constexpr (std::is_same_v) - { - res["value"] = (Json::Int64)val; - } - else if constexpr (std::is_same_v) - { - 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); } -} \ No newline at end of file +}