From c4724add006e62b81f847937db56335a81bdcc74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Mon, 6 Sep 2021 14:41:26 +0200 Subject: [PATCH] Normalise nested `progn` forms in byte-code optimiser * lisp/emacs-lisp/byte-opt.el (byte-optimize-body): Flatten body. This simplifies the source tree and reduces the number of different cases that other optimisations need to take into account. --- lisp/emacs-lisp/byte-opt.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 23c5a566cea..ff512cca36f 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -727,8 +727,12 @@ Same format as `byte-optimize--lexvars', with shared structure and contents.") (while rest (setq fe (or all-for-effect (cdr rest))) (setq new (and (car rest) (byte-optimize-form (car rest) fe))) - (if (or new (not fe)) - (setq result (cons new result))) + (when (and (consp new) (eq (car new) 'progn)) + ;; Flatten `progn' form into the body. + (setq result (append (reverse (cdr new)) result)) + (setq new (pop result))) + (when (or new (not fe)) + (setq result (cons new result))) (setq rest (cdr rest))) (nreverse result))) -- 2.39.2