[Top][All Lists]

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

master fb98c4a406 4/5: Improved `null` (alias `not`) optimisation

From: Mattias Engdegård
Subject: master fb98c4a406 4/5: Improved `null` (alias `not`) optimisation
Date: Tue, 16 Aug 2022 14:45:13 -0400 (EDT)

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

    Improved `null` (alias `not`) optimisation
    Take static boolean information of the argument into account.
    * lisp/emacs-lisp/byte-opt.el (byte-optimize-not): New.
 lisp/emacs-lisp/byte-opt.el | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 74a6523cec..bbe8135f04 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1306,11 +1306,22 @@ See Info node `(elisp) Integer Basics'."
+(defun byte-optimize-not (form)
+  (and (= (length form) 2)
+       (let ((arg (nth 1 form)))
+         (cond ((null arg) t)
+               ((macroexp-const-p arg) nil)
+               ((byte-compile-nilconstp arg) `(progn ,arg t))
+               ((byte-compile-trueconstp arg) `(progn ,arg nil))
+               (t form)))))
 (put 'and   'byte-optimizer #'byte-optimize-and)
 (put 'or    'byte-optimizer #'byte-optimize-or)
 (put 'cond  'byte-optimizer #'byte-optimize-cond)
 (put 'if    'byte-optimizer #'byte-optimize-if)
 (put 'while 'byte-optimizer #'byte-optimize-while)
+(put 'not   'byte-optimizer #'byte-optimize-not)
+(put 'null  'byte-optimizer #'byte-optimize-not)
 ;; byte-compile-negation-optimizer lives in bytecomp.el
 (put '/= 'byte-optimizer #'byte-compile-negation-optimizer)

reply via email to

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