diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2022-07-15 23:42:45 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2022-07-16 12:18:41 +0200 |
commit | d1ac1b2108e0934b11631c39307b208a2c0fdf1a (patch) | |
tree | 55d4c0d42d8e53fa67a380b1dc789f582cb4cae3 /lisp/emacs-lisp | |
parent | eb0e93478e423974fe6c7c7e4d183ea8d9f0e742 (diff) | |
download | emacs-d1ac1b2108e0934b11631c39307b208a2c0fdf1a.tar.gz emacs-d1ac1b2108e0934b11631c39307b208a2c0fdf1a.tar.bz2 emacs-d1ac1b2108e0934b11631c39307b208a2c0fdf1a.zip |
Improved cons optimisation
* lisp/emacs-lisp/byte-opt.el (byte-optimize-cons):
Add the transform
(cons X (list Y...)) -> (list X Y...)
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 5a138e9fee5..480b652342b 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) |