adjust plug to be parsimonious and actually shortcircuit

when one hole has been found

This improves the lambdajs model example's running time, presumably
because the hole is generally found near the "beginning" of the
term
This commit is contained in:
Robby Findler 2012-01-02 05:05:49 -06:00
parent e8beac29cf
commit 6bf42855b8

View File

@ -1779,21 +1779,26 @@ See match-a-pattern.rkt for more details
(define (reverse-context x) (reverse x)) (define (reverse-context x) (reverse x))
(define (build-nested-context c1 c2) (define (build-nested-context c1 c2)
(plug c1 c2)) (plug c1 c2))
(define (plug exp hole-stuff) (define (plug exp hole-stuff)
(let ([done? #f]) (let loop ([exp exp])
(let loop ([exp exp]) (cond
(cond [(pair? exp)
[(pair? exp) (define old-car (car exp))
(cons (loop (car exp)) (define new-car (loop old-car))
(loop (cdr exp)))] (cond
[(eq? the-not-hole exp) [(eq? new-car old-car)
the-not-hole] (define old-cdr (cdr exp))
[(eq? the-hole exp) (define new-cdr (loop old-cdr))
(if done? (if (eq? new-cdr old-cdr)
exp exp
(begin (set! done? #t) (cons new-car new-cdr))]
hole-stuff))] [else (cons new-car (cdr exp))])]
[else exp])))) [(eq? the-not-hole exp)
the-not-hole]
[(eq? the-hole exp)
hole-stuff]
[else exp])))
;; ;;
;; end context adt ;; end context adt