1 USING: kernel cocoa cocoa.types alien.c-types locals math sequences
5 : NS-EACH-BUFFER-SIZE 16 ; inline
7 : (with-enumeration-buffers) ( quot -- )
8 "NSFastEnumerationState" heap-size swap '[
9 NS-EACH-BUFFER-SIZE "id" heap-size * [
12 ] with-malloc ; inline
14 :: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- )
15 object state stackbuf count -> countByEnumeratingWithState:objects:count:
17 state NSFastEnumerationState-itemsPtr [ stackbuf ] unless*
18 '[ _ void*-nth quot call ] each
19 object quot state stackbuf count (NSFastEnumeration-each)
20 ] if ; inline recursive
22 : NSFastEnumeration-each ( object quot -- )
23 [ (NSFastEnumeration-each) ] (with-enumeration-buffers) ; inline
25 : NSFastEnumeration-map ( object quot -- vector )
26 NS-EACH-BUFFER-SIZE <vector>
27 [ '[ @ _ push ] NSFastEnumeration-each ] keep ; inline
29 : NSFastEnumeration>vector ( object -- vector )
30 [ ] NSFastEnumeration-map ;