From 111c32df145b2941e22d89634f89801b84fd32d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Thu, 25 Apr 2013 00:14:51 +0100 Subject: [PATCH] Speed up bootstrapping time without changing binding structure --- ecmalisp.lisp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/ecmalisp.lisp b/ecmalisp.lisp index cdd3a19..fab1811 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -2778,6 +2778,10 @@ b nil)))) +#+common-lisp +(defvar *macroexpander-cache* + (make-hash-table :test #'eq)) + (defun ls-macroexpand-1 (form) (cond ((symbolp form) @@ -2789,17 +2793,22 @@ (let ((macro-binding (macro (car form)))) (if macro-binding (let ((expander (binding-value macro-binding))) - (when (listp expander) - (let ((compiled (eval expander))) - ;; The list representation are useful while - ;; bootstrapping, as we can dump the definition of the - ;; macros easily, but they are slow because we have to - ;; evaluate them and compile them now and again. So, let - ;; us replace the list representation version of the - ;; function with the compiled one. - ;; - #+ecmalisp (setf (binding-value macro-binding) compiled) - (setq expander compiled))) + (cond + #+common-lisp + ((gethash macro-binding *macroexpander-cache*) + (setq expander (gethash macro-binding *macroexpander-cache*))) + ((listp expander) + (let ((compiled (eval expander))) + ;; The list representation are useful while + ;; bootstrapping, as we can dump the definition of the + ;; macros easily, but they are slow because we have to + ;; evaluate them and compile them now and again. So, let + ;; us replace the list representation version of the + ;; function with the compiled one. + ;; + #+ecmalisp (setf (binding-value macro-binding) compiled) + #+common-lisp (setf (gethash macro-binding *macroexpander-cache*) compiled) + (setq expander compiled)))) (values (apply expander (cdr form)) t)) (values form nil)))) (t -- 1.7.10.4