Avoid consing and canonicalizing on every call to expand

This commit is contained in:
Tony Garnock-Jones 2016-03-15 10:52:38 -04:00
parent 482852a6d6
commit 515f8fd9a7
1 changed files with 6 additions and 4 deletions

View File

@ -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.