summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2021-07-20 17:23:11 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2021-07-20 19:21:00 +0200
commit51a86b6a0504d580d3e10efe41abf3ae42c90711 (patch)
tree3d257a1e0ac3cdb27cc0294617be8eea878fe491 /lisp/emacs-lisp
parent0c58796a2224e9b5d97a07033998099609150571 (diff)
downloademacs-51a86b6a0504d580d3e10efe41abf3ae42c90711.tar.gz
emacs-51a86b6a0504d580d3e10efe41abf3ae42c90711.tar.bz2
emacs-51a86b6a0504d580d3e10efe41abf3ae42c90711.zip
Count (not X) as a switch condition
* lisp/emacs-lisp/bytecomp.el (byte-compile--cond-switch-prefix): Treat (not VAR) and (null VAR) as (eq VAR nil) when computing the extent of switch ops.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/bytecomp.el10
1 files changed, 10 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 6970c8a5055..2968f1af5df 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -4340,6 +4340,16 @@ Return (TAIL VAR TEST CASES), where:
(push value keys)
(push (cons (list value) (or body '(t))) cases))
t))))
+ ;; Treat (not X) as (eq X nil).
+ (`((,(or 'not 'null) ,(and var (pred symbolp))) . ,body)
+ (and (or (eq var switch-var) (not switch-var))
+ (progn
+ (setq switch-var var)
+ (setq switch-test 'eq)
+ (unless (memq nil keys)
+ (push nil keys)
+ (push (cons (list nil) (or body '(t))) cases))
+ t)))
(`((,(and fn (or 'memq 'memql 'member)) ,var ,expr) . ,body)
(and (symbolp var)
(or (eq var switch-var) (not switch-var))