]> git.eshelyaron.com Git - emacs.git/commitdiff
Optimise (cons X nil) to (list X)
authorMattias Engdegård <mattiase@acm.org>
Thu, 3 Jun 2021 19:15:11 +0000 (21:15 +0200)
committerMattias Engdegård <mattiase@acm.org>
Thu, 3 Jun 2021 19:28:10 +0000 (21:28 +0200)
* lisp/emacs-lisp/byte-opt.el (byte-optimize-cons): New function.

lisp/emacs-lisp/byte-opt.el

index 10a50da46288203ececaa96343d5bab146fc7fc4..99e84e23ad8c5a4edc437bdb37097be0a978588f 100644 (file)
@@ -1269,6 +1269,14 @@ See Info node `(elisp) Integer Basics'."
        form)
     form))
 
+(put 'cons 'byte-optimizer #'byte-optimize-cons)
+(defun byte-optimize-cons (form)
+  ;; (cons X nil) => (list X)
+  (if (and (= (safe-length form) 3)
+           (null (nth 2 form)))
+      `(list ,(nth 1 form))
+    form))
+
 ;; Fixme: delete-char -> delete-region (byte-coded)
 ;; optimize string-as-unibyte, string-as-multibyte, string-make-unibyte,
 ;; string-make-multibyte for constant args.