summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-08-16 19:03:46 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2022-08-16 20:44:50 +0200
commitfb98c4a4060ee756af41dee7a23472219314d37a (patch)
treef18919c972969c977f129e9de124b9676cf011f2
parent621550c076b135e47cf1a377a779263e12401b8a (diff)
downloademacs-fb98c4a4060ee756af41dee7a23472219314d37a.tar.gz
Improved `null` (alias `not`) optimisation
Take static boolean information of the argument into account. * lisp/emacs-lisp/byte-opt.el (byte-optimize-not): New.
-rw-r--r--lisp/emacs-lisp/byte-opt.el11
1 files changed, 11 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 74a6523cecb..bbe8135f04a 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'."
condition
form)))
+(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)