guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/05: memoization: Add 'invalidate-memoization!.


From: Ludovic Courtès
Subject: 03/05: memoization: Add 'invalidate-memoization!.
Date: Wed, 13 Dec 2017 17:12:10 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit d1f01e48457f8cac9e64fb9f890332d5d93f430e
Author: Ludovic Courtès <address@hidden>
Date:   Wed Dec 13 14:59:48 2017 +0100

    memoization: Add 'invalidate-memoization!.
    
    * guix/memoization.scm (%make-hash-table*): When not profiling, add the
    new table to %MEMOIZATION-TABLES.
    (invalidate-memoization!): New procedure.
---
 guix/memoization.scm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/guix/memoization.scm b/guix/memoization.scm
index 0201fe4..086c4cd 100644
--- a/guix/memoization.scm
+++ b/guix/memoization.scm
@@ -21,7 +21,8 @@
   #:use-module (ice-9 match)
   #:autoload   (srfi srfi-1) (count)
   #:use-module (srfi srfi-9)
-  #:export (memoize
+  #:export (invalidate-memoization!
+            memoize
             mlambda
             mlambdaq))
 
@@ -113,11 +114,21 @@ already-cached result."
                       (cons cache location))
           cache))
       (lambda (proc location)
-        (make-hash-table))))
+        (let ((table (make-hash-table)))
+          (hashq-set! %memoization-tables proc table)
+          table))))
 
 (define-syntax-rule (make-hash-table* proc)
   (%make-hash-table* proc (current-source-location)))
 
+(define (invalidate-memoization! proc)
+  "Invalidate the memoization cache of PROC."
+  (match (hashq-ref %memoization-tables proc)
+    ((? hash-table? table)
+     (hash-clear! table))
+    (((? cache? cache) . _)
+     (hash-clear! (cache-table cache)))))
+
 (define* (show-memoization-tables #:optional (port (current-error-port)))
   "Display to PORT statistics about the memoization tables."
   (define (cache<? p1 p2)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]