diff options
| author | Mark Oteiza | 2017-08-14 01:54:11 -0400 |
|---|---|---|
| committer | Mark Oteiza | 2017-08-14 01:54:11 -0400 |
| commit | ab2da681b904cd0c7bfac3a6f5fb3347cc591f20 (patch) | |
| tree | 086e96b2a670d596f61fc159c5c72a85bec29692 | |
| parent | 5bdc97d55df30f6af107ddd136901983a7e2706a (diff) | |
| download | emacs-ab2da681b904cd0c7bfac3a6f5fb3347cc591f20.tar.gz emacs-ab2da681b904cd0c7bfac3a6f5fb3347cc591f20.zip | |
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.
| -rw-r--r-- | lisp/json.el | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lisp/json.el b/lisp/json.el index 3def94ce042..627e65efa45 100644 --- a/lisp/json.el +++ b/lisp/json.el | |||
| @@ -193,8 +193,7 @@ Unlike `reverse', this keeps the property-value pairs intact." | |||
| 193 | 193 | ||
| 194 | (defsubst json-peek () | 194 | (defsubst json-peek () |
| 195 | "Return the character at point." | 195 | "Return the character at point." |
| 196 | (let ((char (char-after (point)))) | 196 | (or (char-after (point)) :json-eof)) |
| 197 | (or char :json-eof))) | ||
| 198 | 197 | ||
| 199 | (defsubst json-pop () | 198 | (defsubst json-pop () |
| 200 | "Advance past the character at point, returning it." | 199 | "Advance past the character at point, returning it." |
| @@ -415,7 +414,7 @@ representation will be parsed correctly." | |||
| 415 | ;; Skip over the '"' | 414 | ;; Skip over the '"' |
| 416 | (json-advance) | 415 | (json-advance) |
| 417 | (if characters | 416 | (if characters |
| 418 | (apply 'string (nreverse characters)) | 417 | (concat (nreverse characters)) |
| 419 | ""))) | 418 | ""))) |
| 420 | 419 | ||
| 421 | ;; String encoding | 420 | ;; String encoding |
| @@ -639,7 +638,9 @@ become JSON objects." | |||
| 639 | (signal 'json-error (list 'bleah))))) | 638 | (signal 'json-error (list 'bleah))))) |
| 640 | ;; Skip over the "]" | 639 | ;; Skip over the "]" |
| 641 | (json-advance) | 640 | (json-advance) |
| 642 | (apply json-array-type (nreverse elements)))) | 641 | (pcase json-array-type |
| 642 | (`vector (nreverse (vconcat elements))) | ||
| 643 | (`list (nreverse elements))))) | ||
| 643 | 644 | ||
| 644 | ;; Array encoding | 645 | ;; Array encoding |
| 645 | 646 | ||