! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel assocs math accessors destructors fry ;
+USING: kernel assocs math accessors destructors fry sequences ;
IN: cache
-SLOT: age
-
-GENERIC: age ( obj -- )
-
-M: object age [ 1+ ] change-age drop ;
-
TUPLE: cache-assoc assoc max-age disposed ;
: <cache-assoc> ( -- cache )
H{ } clone 10 f cache-assoc boa ;
+<PRIVATE
+
+TUPLE: cache-entry value age ;
+
+: <cache-entry> ( value -- entry ) 0 cache-entry boa ; inline
+
+M: cache-entry dispose value>> dispose ;
+
M: cache-assoc assoc-size assoc>> assoc-size ;
-M: cache-assoc at* assoc>> at* [ dup [ 0 >>age ] when ] dip ;
+M: cache-assoc at* assoc>> at* [ dup [ 0 >>age value>> ] when ] dip ;
-M: cache-assoc set-at dup check-disposed assoc>> set-at ;
+M: cache-assoc set-at
+ [ check-disposed ] keep
+ [ <cache-entry> ] 2dip
+ assoc>> set-at ;
M: cache-assoc clear-assoc assoc>> clear-assoc ;
-M: cache-assoc >alist assoc>> >alist ;
+M: cache-assoc >alist assoc>> [ value>> ] { } assoc-map-as ;
INSTANCE: cache-assoc assoc
+M: cache-assoc dispose*
+ [ values dispose-each ] [ clear-assoc ] bi ;
+
+PRIVATE>
+
: purge-cache ( cache -- )
dup max-age>> '[
- [ nip dup age age>> _ >= ] assoc-partition
+ [ nip [ 1+ ] change-age age>> _ >= ] assoc-partition
[ values dispose-each ] dip
- ] change-assoc drop ;
-
-M: cache-assoc dispose*
- assoc>> [ values dispose-each ] [ clear-assoc ] bi ;
+ ] change-assoc drop ;
\ No newline at end of file
CTLineCreateWithAttributedString
] with-destructors ;
-TUPLE: line font line metrics dim bitmap age disposed ;
+TUPLE: line font line metrics dim bitmap disposed ;
: compute-line-metrics ( line -- line-metrics )
0 <CGFloat> 0 <CGFloat> 0 <CGFloat>
[ [ line ] dip CTLineDraw ]
} cleave
] with-bitmap-context
- [ open-font line metrics dim ] dip 0 f
+ [ open-font line metrics dim ] dip
]
- line boa
+ f line boa
] with-destructors ;
M: line dispose* [ font>> CFRelease ] [ line>> CFRelease ] bi ;
kernel opengl opengl.gl combinators ;
IN: opengl.texture-cache
-TUPLE: texture texture display-list age disposed ;
+TUPLE: texture texture display-list disposed ;
: make-texture-display-list ( dim texture -- dlist )
GL_COMPILE [
{ [ dim>> ] [ bitmap>> ] [ format>> ] [ type>> ] }
cleave make-texture
] [ dim>> ] bi
- over make-texture-display-list 0 f texture boa ;
+ over make-texture-display-list f texture boa ;
M: texture dispose*
[ texture>> delete-texture ]