mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 12:37:08 +11:00
🐎 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:
parent
9f58dda6d2
commit
04bf0c55e4
1 changed files with 2 additions and 25 deletions
|
|
@ -1,35 +1,12 @@
|
||||||
#include "bank_f.h"
|
#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 INLINE __attribute__((always_inline)) inline
|
||||||
#define GEN_BODY \
|
#define GEN_BODY \
|
||||||
const auto temp_req = req->getJsonObject(); \
|
const auto temp_req = req->getJsonObject(); \
|
||||||
const auto body = temp_req ? *temp_req : Json::Value();
|
const auto body = temp_req ? *temp_req : Json::Value();
|
||||||
#define PASS_HEADER req->getHeader("Password")
|
#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) {}
|
BankF::BankF(Bank *b) : bank(*b) {}
|
||||||
|
|
||||||
void BankF::Help(req_args) const
|
void BankF::Help(req_args) const
|
||||||
|
|
@ -118,4 +95,4 @@ void BankF::GetLog(req_args, const std::string &name)
|
||||||
resp->setExpiredTime(0); //cached forever
|
resp->setExpiredTime(0); //cached forever
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue