bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31138: Native json slower than json.el


From: Alex Gramiak
Subject: bug#31138: Native json slower than json.el
Date: Mon, 22 Apr 2019 12:20:15 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

If the validation is done on the Emacs side, then perhaps it would be
beneficial to use the json_*_nocheck function alternatives to disable
libjannson's validation, namely json_stringn_nocheck and
json_object_set_new_nocheck.

[1] jansson.readthedocs.io/en/stable/apiref.html#c.json_stringn_nocheck

P.S. Would applying the following diff be okay? It's a simple
optimization that avoids an overflow check (the sizeof comparison is
optimized out even in -O0) in the usual case of a JSON integer fitting
into an EMACS_INT.

diff --git a/src/json.c b/src/json.c
index 928825e034..9faf1f80ca 100644
--- a/src/json.c
+++ b/src/json.c
@@ -836,7 +836,10 @@ json_to_lisp (json_t *json, struct json_configuration 
*conf)
     case JSON_INTEGER:
       {
        json_int_t i = json_integer_value (json);
-       return INT_TO_INTEGER (i);
+        if (sizeof (json_int_t) <= sizeof (EMACS_INT))
+          return make_fixnum (i);
+        else
+          return INT_TO_INTEGER (i);
       }
     case JSON_REAL:
       return make_float (json_real_value (json));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]