emacs-diffs
[Top][All Lists]
Advanced

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

master d1ac1b2108 2/3: Improved cons optimisation


From: Mattias Engdegård
Subject: master d1ac1b2108 2/3: Improved cons optimisation
Date: Sat, 16 Jul 2022 06:32:27 -0400 (EDT)

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

    Improved cons optimisation
    
    * lisp/emacs-lisp/byte-opt.el (byte-optimize-cons):
    Add the transform
    
     (cons X (list Y...)) -> (list X Y...)
---
 lisp/emacs-lisp/byte-opt.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 5a138e9fee..480b652342 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1281,11 +1281,14 @@ See Info node `(elisp) Integer Basics'."
 
 (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))
+  (let ((tail (nth 2 form)))
+    (cond
+     ;; (cons X nil) => (list X)
+     ((null tail) `(list ,(nth 1 form)))
+     ;; (cons X (list YS...)) -> (list X YS...)
+     ((and (consp tail) (eq (car tail) 'list))
+      `(,(car tail) ,(nth 1 form) . ,(cdr tail)))
+     (t form))))
 
 (put 'list 'byte-optimizer #'byte-optimize-list)
 (defun byte-optimize-list (form)



reply via email to

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