attempted microoptimization in eval.scm.
authorAndy Wingo <wingo@pobox.com>
Sun, 13 Jun 2010 18:17:49 +0000 (20:17 +0200)
committerAndy Wingo <wingo@pobox.com>
Sun, 13 Jun 2010 18:17:49 +0000 (20:17 +0200)
* module/ice-9/eval.scm (primitive-eval): Try using list-ref instead of
  cdring in the vm. We'll check the hydra build times to see if this has
  any actual merit. Surely the best solution is another representation
  of environments, though.

module/ice-9/eval.scm

index c16f08e..30a373a 100644 (file)
@@ -46,6 +46,9 @@
 (eval-when (compile)
   (define-syntax capture-env
     (syntax-rules ()
+      ((_ (exp ...))
+       (let ((env (exp ...)))
+         (capture-env env)))
       ((_ env)
        (if (null? env)
            (current-module)
     (define (eval exp env)
       (memoized-expression-case exp
         (('lexical-ref n)
-         (let lp ((n n) (env env))
-           (if (zero? n)
-               (car env)
-               (lp (1- n) (cdr env)))))
-      
+         (list-ref env n))
+        
         (('call (f nargs . args))
          (let ((proc (eval f env)))
            (call eval proc nargs args env)))
          (variable-ref
           (if (variable? var-or-sym)
               var-or-sym
-              (let lp ((env env))
-                (if (pair? env)
-                    (lp (cdr env))
-                    (memoize-variable-access! exp (capture-env env)))))))
+              (memoize-variable-access! exp
+                                        (capture-env (if (pair? env)
+                                                         (cdr (last-pair env))
+                                                         env))))))
 
         (('if (test consequent . alternate))
          (if (eval test env)
       
         (('lexical-set! (n . x))
          (let ((val (eval x env)))
-           (let lp ((n n) (env env))
-             (if (zero? n)
-                 (set-car! env val)
-                 (lp (1- n) (cdr env))))))
+           (list-set! env n val)))
         
         (('call-with-values (producer . consumer))
          (call-with-values (eval producer env)
          (variable-set!
           (if (variable? var-or-sym)
               var-or-sym
-              (let lp ((env env))
-                (if (pair? env)
-                    (lp (cdr env))
-                    (memoize-variable-access! exp (capture-env env)))))
+              (memoize-variable-access! exp
+                                        (capture-env (if (pair? env)
+                                                         (cdr (last-pair env))
+                                                         env))))
           (eval x env)))
       
         (('dynwind (in exp . out))