1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Optimise (cons X nil) to (list X)

* lisp/emacs-lisp/byte-opt.el (byte-optimize-cons): New function.
This commit is contained in:
Mattias Engdegård 2021-06-03 21:15:11 +02:00
parent c3b44858dc
commit a517b77ffe

View 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.