From 21cd97f2b2b8dbf3399404e4b63e304a77476c07 Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Sat, 7 Nov 2020 12:14:55 +0200 Subject: [PATCH] match: stop searching for unused tmps when all have been found --- racket/collects/racket/match/compiler.rkt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/racket/collects/racket/match/compiler.rkt b/racket/collects/racket/match/compiler.rkt index 706a4633b6..62756d1c64 100644 --- a/racket/collects/racket/match/compiler.rkt +++ b/racket/collects/racket/match/compiler.rkt @@ -138,10 +138,16 @@ ;; present in `body'. (define (remove-unused-tmps tmps accs body) (define seen (make-hasheq)) + (define todo (make-hasheq + (for/list ([tmp (in-list (syntax-e tmps))]) + (cons tmp #t)))) (let loop ([stx body]) (cond + ;; stop the search early if all the tmps have already been found + [(hash-empty? todo)] [(identifier? stx) - (for/first ([tmp (in-list (syntax-e tmps))] #:when (free-identifier=? tmp stx)) + (for/first ([tmp (in-list (hash-keys todo))] #:when (free-identifier=? tmp stx)) + (hash-remove! todo tmp) (hash-set! seen tmp #t))] [(list? (syntax-e stx)) (for-each loop (syntax-e stx))]))