[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Mark Oteiza |
Subject: |
|
Date: |
Wed, 30 Aug 2017 15:33:30 -0400 |
Hi,
I wrote the following to get rid of the 'apply' here. The
expansion is something that, according to how byte-switch is described,
should compile to a switch/jumptable, but it isn't happening.
Applying the following, doing M-x byte-compile-file, and inspecting the
.elc/disassembly I am seeing a series of goto-if-nil. Am I doing
something wrong?
diff --git a/lisp/json.el b/lisp/json.el
index 64486258cc..6990ddd0f5 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -683,6 +683,23 @@ json-readtable
table)
"Readtable for JSON reader.")
+(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)))
+ 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 `((= ,char ,c) (,@rest)) res))
+ `(cond ,@res (t (signal 'json-readtable-error ,char)))))
+
(defun json-read ()
"Parse and return the JSON object following point.
Advances point just past JSON object."
@@ -690,10 +707,7 @@ json-read
(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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [no subject],
Mark Oteiza <=