[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 51a86b6 1/2: Count (not X) as a switch condition

From: Mattias Engdegård
Subject: master 51a86b6 1/2: Count (not X) as a switch condition
Date: Tue, 20 Jul 2021 13:31:26 -0400 (EDT)

branch: master
commit 51a86b6a0504d580d3e10efe41abf3ae42c90711
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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.
 lisp/emacs-lisp/bytecomp.el | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 6970c8a..2968f1a 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))
+             ;; 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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]