From: Mattias EngdegÄrd Date: Thu, 3 Jun 2021 19:15:11 +0000 (+0200) Subject: Optimise (cons X nil) to (list X) X-Git-Tag: emacs-28.0.90~2206 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a517b77ffe8ed8cdfeec1a9b5258fd16b2446214;p=emacs.git Optimise (cons X nil) to (list X) * lisp/emacs-lisp/byte-opt.el (byte-optimize-cons): New function. --- diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 10a50da4628..99e84e23ad8 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.