From 04f855bc7002817295a88cfb4f2eb11495c051b3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 27 Dec 2018 14:04:10 -0800 Subject: [PATCH] cache annotations refs --- pitfall/pitfall/annotations.rkt | 46 ++++++++++++++++++++++----------- pitfall/pitfall/document.rkt | 2 ++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/pitfall/pitfall/annotations.rkt b/pitfall/pitfall/annotations.rkt index 3be9b987..bb09a81d 100644 --- a/pitfall/pitfall/annotations.rkt +++ b/pitfall/pitfall/annotations.rkt @@ -9,6 +9,12 @@ (provide (all-defined-out)) +(define annots-cache (make-hash)) +(define link-ref-cache (make-hash)) +(define (reset-annotations-cache!) + (set! link-ref-cache (make-hash)) + (set! annots-cache (make-hash))) + (define (annotate doc x y w h options) (hash-set*! options 'Type 'Annot @@ -23,28 +29,38 @@ (for ([(k v) (in-hash options)]) (hash-set! options (string->symbol (string-titlecase (symbol->string k))) v)) - (define annots-ref (make-ref options)) + ;; reuse previous identical annotations (= fewer refs in file) + (define annots-ref + (hash-ref! annots-cache (sort (hash->list options) #:key car symbol