1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

Eval speedup for lexical-ref

* module/ice-9/eval.scm (primitive-eval): Specialize lexical-ref for
  depths 0, 1, and 2.  Speeds up this test by around 13%:

    (primitive-eval '(let lp ((n 0)) (when (< n #e1e7) (lp (1+ n)))))
This commit is contained in:
Andy Wingo 2015-11-11 14:51:19 +01:00
parent ac5a05d02e
commit 25738ec35d

View file

@ -119,8 +119,11 @@
(proc arg ...)))) (proc arg ...))))
(define (compile-lexical-ref depth width) (define (compile-lexical-ref depth width)
(lambda (env) (case depth
(env-ref env depth width))) ((0) (lambda (env) (env-ref env 0 width)))
((1) (lambda (env) (env-ref env 1 width)))
((2) (lambda (env) (env-ref env 2 width)))
(else (lambda (env) (env-ref env depth width)))))
(define (primitive=? name loc module var) (define (primitive=? name loc module var)
"Return true if VAR is the same as the primitive bound to NAME." "Return true if VAR is the same as the primitive bound to NAME."