Improved cons optimisation
* lisp/emacs-lisp/byte-opt.el (byte-optimize-cons): Add the transform (cons X (list Y...)) -> (list X Y...)
This commit is contained in:
parent
eb0e93478e
commit
d1ac1b2108
1 changed files with 8 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue