Commit ab2da681 authored by Mark Oteiza's avatar Mark Oteiza

Tiny JSON performance improvement

Get rid of some needless uses of apply.  Measuring with
  (benchmark-run 10 (json-read-file "test.json"))
showed 1.5-2.5% reduction of execution time.
* lisp/json.el (json-peek): Nix let-binding.
(json-read-string): Use concat for making a string from chars.
(json-read-array): Use cond and more appropriate conversion instead
of blindly applying.
parent 5bdc97d5
......@@ -193,8 +193,7 @@ Unlike `reverse', this keeps the property-value pairs intact."
(defsubst json-peek ()
"Return the character at point."
(let ((char (char-after (point))))
(or char :json-eof)))
(or (char-after (point)) :json-eof))
(defsubst json-pop ()
"Advance past the character at point, returning it."
......@@ -415,7 +414,7 @@ representation will be parsed correctly."
;; Skip over the '"'
(if characters
(apply 'string (nreverse characters))
(concat (nreverse characters))
;; String encoding
......@@ -639,7 +638,9 @@ become JSON objects."
(signal 'json-error (list 'bleah)))))
;; Skip over the "]"
(apply json-array-type (nreverse elements))))
(pcase json-array-type
(`vector (nreverse (vconcat elements)))
(`list (nreverse elements)))))
;; Array encoding
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment