malloc the NSFastEnumeration buffers because the class implementation might store pointers into the buffers in the enumeration state
parent
8174a0967c
commit
310acd52c5
|
@ -1,28 +1,30 @@
|
||||||
USING: kernel cocoa cocoa.types alien.c-types locals math sequences
|
USING: kernel cocoa cocoa.types alien.c-types locals math sequences
|
||||||
vectors fry ;
|
vectors fry libc ;
|
||||||
IN: cocoa.enumeration
|
IN: cocoa.enumeration
|
||||||
|
|
||||||
: NS-EACH-BUFFER-SIZE 16 ; inline
|
: NS-EACH-BUFFER-SIZE 16 ; inline
|
||||||
|
|
||||||
: (allocate-enumeration-buffers) ( -- state stackbuf count )
|
: (with-enumeration-buffers) ( quot -- )
|
||||||
"NSFastEnumerationState" <c-object>
|
"NSFastEnumerationState" heap-size swap '[
|
||||||
NS-EACH-BUFFER-SIZE "id" <c-array>
|
NS-EACH-BUFFER-SIZE "id" heap-size * [
|
||||||
NS-EACH-BUFFER-SIZE ;
|
NS-EACH-BUFFER-SIZE @
|
||||||
|
] with-malloc
|
||||||
|
] with-malloc ; inline
|
||||||
|
|
||||||
:: (NSFastEnumeration-each) ( object quot state stackbuf count -- )
|
:: (NSFastEnumeration-each) ( object quot state stackbuf count -- )
|
||||||
object state stackbuf count -> countByEnumeratingWithState:objects:count:
|
object state stackbuf count -> countByEnumeratingWithState:objects:count:
|
||||||
dup zero? [ drop ] [
|
dup zero? [ drop ] [
|
||||||
[
|
state NSFastEnumerationState-itemsPtr [ stackbuf ] unless*
|
||||||
state NSFastEnumerationState-itemsPtr dup stackbuf ?
|
'[ , void*-nth quot call ] each
|
||||||
void*-nth quot call
|
object quot state stackbuf count (NSFastEnumeration-each)
|
||||||
] each object quot state stackbuf count (NSFastEnumeration-each)
|
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
: NSFastEnumeration-each ( object quot -- )
|
: NSFastEnumeration-each ( object quot -- )
|
||||||
(allocate-enumeration-buffers) (NSFastEnumeration-each) ; inline
|
[ (NSFastEnumeration-each) ] (with-enumeration-buffers) ; inline
|
||||||
|
|
||||||
: NSFastEnumeration-map ( object quot -- vector )
|
: NSFastEnumeration-map ( object quot -- vector )
|
||||||
NS-EACH-BUFFER-SIZE <vector> [ '[ @ , push ] NSFastEnumeration-each ] keep ; inline
|
NS-EACH-BUFFER-SIZE <vector>
|
||||||
|
[ '[ @ , push ] NSFastEnumeration-each ] keep ; inline
|
||||||
|
|
||||||
: NSFastEnumeration>vector ( object -- vector )
|
: NSFastEnumeration>vector ( object -- vector )
|
||||||
[ ] NSFastEnumeration-map ;
|
[ ] NSFastEnumeration-map ;
|
||||||
|
|
Loading…
Reference in New Issue