]> gitweb.factorcode.org Git - factor.git/blob - basis/cocoa/enumeration/enumeration.factor
Fix conflict
[factor.git] / basis / cocoa / enumeration / enumeration.factor
1 ! Copyright (C) 2008 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel cocoa cocoa.types alien.c-types locals math
4 sequences vectors fry libc destructors
5 specialized-arrays.direct.alien ;
6 IN: cocoa.enumeration
7
8 CONSTANT: NS-EACH-BUFFER-SIZE 16
9
10 : with-enumeration-buffers ( quot -- )
11     '[
12         "NSFastEnumerationState" malloc-object &free
13         NS-EACH-BUFFER-SIZE "id" malloc-array &free
14         NS-EACH-BUFFER-SIZE
15         @
16     ] with-destructors ; inline
17
18 :: (NSFastEnumeration-each) ( object quot: ( elt -- ) state stackbuf count -- )
19     object state stackbuf count -> countByEnumeratingWithState:objects:count:
20     dup 0 = [ drop ] [
21         state NSFastEnumerationState-itemsPtr [ stackbuf ] unless*
22         swap <direct-void*-array> quot each
23         object quot state stackbuf count (NSFastEnumeration-each)
24     ] if ; inline recursive
25
26 : NSFastEnumeration-each ( object quot -- )
27     [ (NSFastEnumeration-each) ] with-enumeration-buffers ; inline
28
29 : NSFastEnumeration-map ( object quot -- vector )
30     NS-EACH-BUFFER-SIZE <vector>
31     [ '[ @ _ push ] NSFastEnumeration-each ] keep ; inline
32
33 : NSFastEnumeration>vector ( object -- vector )
34     [ ] NSFastEnumeration-map ;