mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Optimise the maths for the jsonrpc oversize integer workaround.
This commit is contained in:
@@ -814,14 +814,14 @@ module
|
||||
* The maximum number of bits an integer can be have in its native type.
|
||||
*
|
||||
* By default Anope will emit integers as their native JSON type. If you are
|
||||
* using JavaScript (which has 56 bit integers) or another language with
|
||||
* using JavaScript (which has 53 bit integers) or another language with
|
||||
* native integer types smaller than 64 bits you may need to limit the size
|
||||
* of integers emitted by Anope.
|
||||
*
|
||||
* If this is enabled a string will be used for values outside of the range
|
||||
* supported by the native data type.
|
||||
*/
|
||||
#integer_bits = 56
|
||||
#integer_bits = 53
|
||||
|
||||
/* Web service to use. Requires httpd. */
|
||||
server = "httpd/main"
|
||||
|
||||
@@ -239,8 +239,7 @@ yyjson_mut_val *JSONRPCServiceInterface::SerializeElement(yyjson_mut_doc *doc, c
|
||||
},
|
||||
[&doc, &elem](int64_t i)
|
||||
{
|
||||
auto bits = std::floor(std::log2(abs(i))) + 1;
|
||||
if (bits <= integer_bits)
|
||||
if (std::abs(i) < (1LL << integer_bits))
|
||||
{
|
||||
// We can fit this into an integer.
|
||||
elem = yyjson_mut_int(doc, i);
|
||||
@@ -254,8 +253,7 @@ yyjson_mut_val *JSONRPCServiceInterface::SerializeElement(yyjson_mut_doc *doc, c
|
||||
},
|
||||
[&doc, &elem](uint64_t u)
|
||||
{
|
||||
auto bits = std::floor(std::log2(u)) + 1;
|
||||
if (bits <= integer_bits)
|
||||
if (u < (1ULL << integer_bits))
|
||||
{
|
||||
// We can fit this into an integer.
|
||||
elem = yyjson_mut_uint(doc, u);
|
||||
|
||||
Reference in New Issue
Block a user