From 515f8fd9a7b90e222cbeca1de56265f716c04158 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 15 Mar 2016 10:52:38 -0400 Subject: [PATCH] Avoid consing and canonicalizing on every call to expand --- prospect/trie.rkt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/prospect/trie.rkt b/prospect/trie.rkt index a335ff2..d99cbc7 100644 --- a/prospect/trie.rkt +++ b/prospect/trie.rkt @@ -264,10 +264,12 @@ ;; Trie -> Trie ;; Given a non-empty trie, returns it; otherwise, returns a branch ;; that is equivalent to the empty trie. Inverse of `collapse`. -(define (expand r) - (if (trie-empty? r) - (canonicalize (branch empty-omap trie-empty empty-smap)) - r)) +(define expand + (let ((canonical-expanded-empty (canonicalize (branch empty-omap trie-empty empty-smap)))) + (lambda (r) + (if (trie-empty? r) + canonical-expanded-empty + r)))) ;; Sigma Trie -> Trie ;; Prepends e to r, if r is non-empty.