From 1724860be24a4dbf830dbdfa78b12b9fbae28bce Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 13 Mar 2016 10:39:02 +0000 Subject: [PATCH] Only canonicalize non (symbol/fixnum/struct-type)s, since these are already unique --- prospect/canonicalize.rkt | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/prospect/canonicalize.rkt b/prospect/canonicalize.rkt index 971112d..979a980 100644 --- a/prospect/canonicalize.rkt +++ b/prospect/canonicalize.rkt @@ -8,16 +8,23 @@ (define sentinel (cons #f #f)) (define (canonicalize val) - (define b (hash-ref canonical-values - val - (lambda () - (define new-b (make-weak-box val)) - (hash-set! canonical-values val new-b) - #f))) - (if (not b) - (canonicalize val) - (let ((v (weak-box-value b sentinel))) - (if (eq? v sentinel) (canonicalize val) v)))) + (cond + [(or (struct-type? val) + (symbol? val) + (fixnum? val)) + ;; These values already have unique representations. + val] + [else + (define b (hash-ref canonical-values + val + (lambda () + (define new-b (make-weak-box val)) + (hash-set! canonical-values val new-b) + #f))) + (if (not b) + (canonicalize val) + (let ((v (weak-box-value b sentinel))) + (if (eq? v sentinel) (canonicalize val) v)))])) (module+ test (require rackunit)