Better 'prog1' optimisation

* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
Always evaporate 'prog1' when the tail is effect-free, even
when the value expression isn't.
This commit is contained in:
Mattias Engdegård 2026-02-11 18:42:46 +01:00
parent 2e7a066d56
commit badef58d0a

View file

@ -345,9 +345,9 @@ There can be multiple entries for the same NAME if it has several aliases.")
(let ((exp-opt (byte-optimize-form exp for-effect)))
(if exps
(let ((exps-opt (byte-optimize-body exps t)))
(if (macroexp-const-p exp-opt)
`(progn ,@exps-opt ,exp-opt)
`(,fn ,exp-opt ,@exps-opt)))
(cond ((null exps-opt) exp-opt)
((macroexp-const-p exp-opt) `(progn ,@exps-opt ,exp-opt))
(t `(,fn ,exp-opt ,@exps-opt))))
exp-opt)))
(`(,(or `save-excursion `save-restriction `save-current-buffer) . ,exps)