| 
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 |  |  | ! Copyright (C) 2008 Joe Groff. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2014-07-08 19:12:41 -04:00
										 |  |  | USING: accessors alien.data assocs classes.struct cocoa | 
					
						
							|  |  |  | cocoa.runtime cocoa.types destructors fry hashtables kernel libc | 
					
						
							|  |  |  | locals sequences specialized-arrays vectors ;
 | 
					
						
							| 
									
										
										
										
											2009-09-17 23:07:21 -04:00
										 |  |  | SPECIALIZED-ARRAY: id | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | IN: cocoa.enumeration | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-22 20:13:08 -05:00
										 |  |  | CONSTANT: NS-EACH-BUFFER-SIZE 16
 | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 |  |  | : with-enumeration-buffers ( quot -- )
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  |     '[ | 
					
						
							| 
									
										
										
										
											2009-08-29 13:22:55 -04:00
										 |  |  |         NSFastEnumerationState malloc-struct &free | 
					
						
							| 
									
										
										
										
											2009-09-17 23:07:21 -04:00
										 |  |  |         NS-EACH-BUFFER-SIZE id malloc-array &free | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  |         NS-EACH-BUFFER-SIZE | 
					
						
							|  |  |  |         @ | 
					
						
							| 
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 |  |  |     ] with-destructors ; inline
 | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 02:38:10 -05:00
										 |  |  | :: (NSFastEnumeration-each) ( ... object quot: ( ... elt -- ) state stackbuf count -- ... )
 | 
					
						
							| 
									
										
										
										
											2009-08-29 13:22:55 -04:00
										 |  |  |     object state stackbuf count -> countByEnumeratingWithState:objects:count: :> items-count | 
					
						
							|  |  |  |     items-count 0 = [ | 
					
						
							| 
									
										
										
										
											2009-09-17 23:07:21 -04:00
										 |  |  |         state itemsPtr>> [ items-count id <c-direct-array> ] [ stackbuf ] if* :> items | 
					
						
							| 
									
										
										
										
											2009-08-29 13:22:55 -04:00
										 |  |  |         items-count iota [ items nth quot call ] each
 | 
					
						
							| 
									
										
										
										
											2008-07-13 15:48:59 -04:00
										 |  |  |         object quot state stackbuf count (NSFastEnumeration-each) | 
					
						
							| 
									
										
										
										
											2009-08-29 13:22:55 -04:00
										 |  |  |     ] unless ; inline recursive
 | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 02:38:10 -05:00
										 |  |  | : NSFastEnumeration-each ( ... object quot: ( ... elt -- ... ) -- ... )
 | 
					
						
							| 
									
										
										
										
											2008-12-02 03:44:19 -05:00
										 |  |  |     [ (NSFastEnumeration-each) ] with-enumeration-buffers ; inline
 | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 02:38:10 -05:00
										 |  |  | : NSFastEnumeration-map ( ... object quot: ( ... elt -- ... newelt ) -- ... vector )
 | 
					
						
							| 
									
										
										
										
											2008-07-13 15:48:59 -04:00
										 |  |  |     NS-EACH-BUFFER-SIZE <vector>
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:40 -04:00
										 |  |  |     [ '[ @ _ push ] NSFastEnumeration-each ] keep ; inline
 | 
					
						
							| 
									
										
										
										
											2008-07-13 13:42:35 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : NSFastEnumeration>vector ( object -- vector )
 | 
					
						
							|  |  |  |     [ ] NSFastEnumeration-map ;
 | 
					
						
							| 
									
										
										
										
											2014-07-08 19:12:41 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : NSFastEnumeration>hashtable ( ... object quot: ( ... elt -- ... key value ) -- ... vector )
 | 
					
						
							|  |  |  |     NS-EACH-BUFFER-SIZE <hashtable> | 
					
						
							|  |  |  |     [ '[ @ swap _ set-at ] NSFastEnumeration-each ] keep ; inline
 |