From: Mattias EngdegÄrd Date: Sun, 4 Jun 2023 13:58:44 +0000 (+0200) Subject: Better internal-make-closure optimisation X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6058b4559d4b7d42bbcb6da787a95334aa8994ca;p=emacs.git Better internal-make-closure optimisation * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Optimise closed-over values in closure creation like any other, which can lead to stack variables being eliminated. --- diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 562f21aa751..f64674d5a6c 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -447,16 +447,10 @@ for speeding up processing.") . ,(byte-optimize-body exps for-effect))) ;; Needed as long as we run byte-optimize-form after cconv. - (`(internal-make-closure . ,_) - (and (not for-effect) - (progn - ;; Look up free vars and mark them to be kept, so that they - ;; won't be optimized away. - (dolist (var (caddr form)) - (let ((lexvar (assq var byte-optimize--lexvars))) - (when lexvar - (setcar (cdr lexvar) t)))) - form))) + (`(internal-make-closure ,vars ,env . ,rest) + (if for-effect + `(progn ,@(byte-optimize-body env t)) + `(,fn ,vars ,(mapcar #'byte-optimize-form env) . ,rest))) (`((lambda . ,_) . ,_) (let ((newform (macroexp--unfold-lambda form)))