emacs-diffs
[Top][All Lists]
Advanced

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

master a517b77 1/2: Optimise (cons X nil) to (list X)


From: Mattias Engdegård
Subject: master a517b77 1/2: Optimise (cons X nil) to (list X)
Date: Thu, 3 Jun 2021 15:35:21 -0400 (EDT)

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

    Optimise (cons X nil) to (list X)
    
    * lisp/emacs-lisp/byte-opt.el (byte-optimize-cons): New function.
---
 lisp/emacs-lisp/byte-opt.el | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 10a50da..99e84e2 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -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.



reply via email to

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