From 9314e6c56e248a5060a6c125e2088c4fbffe123b Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Mon, 4 Sep 2017 03:40:30 -0400 Subject: [PATCH] Embed JSON readtable into json-read Also unroll dispatch into a cond. * lisp/json.el (json-readtable): Remove. (json-readtable-dispatch): New macro. Assimilate json-readtable. (json-read): Use the macro. --- lisp/json.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lisp/json.el b/lisp/json.el index 64486258ccf..025a77d4b08 100644 --- a/lisp/json.el +++ b/lisp/json.el @@ -669,19 +669,22 @@ become JSON objects." ;;; JSON reader. -(defvar json-readtable +(defmacro json-readtable-dispatch (char) + "Dispatch reader function for CHAR." + (declare (debug (symbolp))) (let ((table '((?t json-read-keyword "true") (?f json-read-keyword "false") (?n json-read-keyword "null") (?{ json-read-object) (?\[ json-read-array) - (?\" json-read-string)))) - (mapc (lambda (char) - (push (list char 'json-read-number) table)) - '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) - table) - "Readtable for JSON reader.") + (?\" json-read-string))) + res) + (dolist (c '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) + (push (list c 'json-read-number) table)) + (pcase-dolist (`(,c . ,rest) table) + (push `((eq ,char ,c) (,@rest)) res)) + `(cond ,@res (t (signal 'json-readtable-error ,char))))) (defun json-read () "Parse and return the JSON object following point. @@ -690,10 +693,7 @@ Advances point just past JSON object." (let ((char (json-peek))) (if (zerop char) (signal 'json-end-of-file nil) - (let ((record (cdr (assq char json-readtable)))) - (if (functionp (car record)) - (apply (car record) (cdr record)) - (signal 'json-readtable-error record)))))) + (json-readtable-dispatch char)))) ;; Syntactic sugar for the reader -- 2.39.2