]> git.eshelyaron.com Git - emacs.git/commitdiff
Generalise CPS-conversion let optimisation
authorMattias Engdegård <mattiase@acm.org>
Tue, 30 Nov 2021 14:04:46 +0000 (15:04 +0100)
committerMattias Engdegård <mattiase@acm.org>
Tue, 30 Nov 2021 14:06:27 +0000 (15:06 +0100)
* lisp/emacs-lisp/generator.el (cps--transform-1):
Eliminate a temporary for the last of any `let` form, not just for
single-binding ones.  Suggested by Stefan Monnier.

lisp/emacs-lisp/generator.el

index 4e286ed7ec4f22883659a2000be3aa0749cb7f22..cb0241017a023569163d5dbb1225c0198b9f7a05 100644 (file)
@@ -294,26 +294,25 @@ DYNAMIC-VAR bound to STATIC-VAR."
     (`(,(or 'let 'let*) () . ,body)
       (cps--transform-1 `(progn ,@body) next-state))
 
-    (`(let (,binding) . ,body)
-      (cps--transform-1 `(let* (,binding) ,@body) next-state))
-
     ;; Transform multi-variable `let' into `let*':
     ;;    (let ((v1 e1) ... (vN eN)) BODY)
-    ;; -> (let* ((t1 e1) ... (tN eN) (v1 t1) (vN tN)) BODY)
+    ;; -> (let* ((t1 e1) ... (tN-1 eN-1) (vN eN) (v1 t1) (vN-1 tN-1)) BODY)
 
     (`(let ,bindings . ,body)
       (let* ((bindings (cl-loop for binding in bindings
                           collect (if (symbolp binding)
                                       (list binding nil)
                                     binding)))
-             (temps (cl-loop for (var _value-form) in bindings
+             (butlast-bindings (butlast bindings))
+             (temps (cl-loop for (var _value-form) in butlast-bindings
                        collect (cps--add-binding var))))
         (cps--transform-1
          `(let* ,(append
-                  (cl-loop for (_var value-form) in bindings
+                  (cl-loop for (_var value-form) in butlast-bindings
                      for temp in temps
                      collect (list temp value-form))
-                  (cl-loop for (var _binding) in bindings
+                  (last bindings)
+                  (cl-loop for (var _binding) in butlast-bindings
                      for temp in temps
                      collect (list var temp)))
             ,@body)