]> git.eshelyaron.com Git - emacs.git/commitdiff
Count (not X) as a switch condition
authorMattias Engdegård <mattiase@acm.org>
Tue, 20 Jul 2021 15:23:11 +0000 (17:23 +0200)
committerMattias Engdegård <mattiase@acm.org>
Tue, 20 Jul 2021 17:21:00 +0000 (19:21 +0200)
* 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.

lisp/emacs-lisp/bytecomp.el

index 6970c8a5055e8eedc6daea35012f5d63547cb071..2968f1af5df5e573b33ef730ca0cd671c99ddd98 100644 (file)
@@ -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))