From 40fafc21621fd7f5e7164bee1813a9819cab8236 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 23 Aug 2007 19:56:16 +0000 Subject: [PATCH] (byte-optimize-if): Move `progn' out of the test so as to optimise cases where the `progn's result is constant. --- lisp/ChangeLog | 9 +++++++-- lisp/emacs-lisp/byte-opt.el | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 947682cdc17..dadc3e0f78c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,7 +1,12 @@ +2007-08-23 Stefan Monnier + + * emacs-lisp/byte-opt.el (byte-optimize-if): Move `progn' out of the test + so as to optimise cases where the `progn's result is constant. + 2007-08-23 Thien-Thi Nguyen - * locate.el (locate-get-file-positions): Use - line-beginning-position and line-end-position. + * locate.el (locate-get-file-positions): + Use line-beginning-position and line-end-position. 2007-08-23 John Wiegley diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 82a5cf0a75a..b4eaf4ff5eb 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -31,7 +31,7 @@ ;; "No matter how hard you try, you can't make a racehorse out of a pig. ;; You can, however, make a faster pig." ;; -;; Or, to put it another way, the emacs byte compiler is a VW Bug. This code +;; Or, to put it another way, the Emacs byte compiler is a VW Bug. This code ;; makes it be a VW Bug with fuel injection and a turbocharger... You're ;; still not going to make it go faster than 70 mph, but it might be easier ;; to get it there. @@ -1014,12 +1014,21 @@ form)) (defun byte-optimize-if (form) + ;; (if (progn ) ) ==> (progn (if )) ;; (if ) ==> ;; (if ) ==> (progn ) ;; (if nil ) ==> (if (not ) (progn )) ;; (if nil) ==> (if ) (let ((clause (nth 1 form))) - (cond ((byte-compile-trueconstp clause) + (cond ((eq (car clause) 'progn) + (if (null (cddr clause)) + ;; A trivial `progn'. + (byte-optimize-if `(if ,(cadr clause) ,@(nthcdr 2 form))) + (nconc (butlast clause) + (list + (byte-optimize-if + `(if ,(car (last clause)) ,@(nthcdr 2 form))))))) + ((byte-compile-trueconstp clause) (nth 2 form)) ((null clause) (if (nthcdr 4 form) @@ -1326,7 +1335,7 @@ ;; This list contains numbers, which are pc values, ;; before each instruction. (defun byte-decompile-bytecode (bytes constvec) - "Turns BYTECODE into lapcode, referring to CONSTVEC." + "Turn BYTECODE into lapcode, referring to CONSTVEC." (let ((byte-compile-constants nil) (byte-compile-variables nil) (byte-compile-tag-number 0)) -- 2.39.2