cache: faster purge-cache.

db4
John Benediktsson 2013-03-06 09:17:35 -08:00
parent 87d65d66d6
commit 45f49775ec
1 changed files with 9 additions and 8 deletions

View File

@ -1,6 +1,7 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel assocs math accessors destructors fry sequences ; USING: accessors assocs continuations destructors fry kernel
make math sequences ;
IN: cache IN: cache
TUPLE: cache-assoc < disposable assoc max-age ; TUPLE: cache-assoc < disposable assoc max-age ;
@ -26,9 +27,7 @@ M: cache-assoc set-at
assoc>> set-at ; assoc>> set-at ;
M: cache-assoc clear-assoc M: cache-assoc clear-assoc
[ assoc>> values dispose-each ] assoc>> [ values dispose-each ] [ clear-assoc ] bi ;
[ assoc>> clear-assoc ]
bi ;
M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ; M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ;
@ -39,7 +38,9 @@ M: cache-assoc dispose* clear-assoc ;
PRIVATE> PRIVATE>
: purge-cache ( cache -- ) : purge-cache ( cache -- )
dup max-age>> '[ [ assoc>> ] [ max-age>> ] bi '[
[ nip [ 1 + ] change-age age>> _ < ] assoc-partition [
values dispose-each nip dup age>> 1 + [ >>age ] keep
] change-assoc drop ; _ < [ drop t ] [ dispose, f ] if
] assoc-filter! drop
] { } make [ last rethrow ] unless-empty ;