Add fast enumeration

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27711 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-01-28 12:03:41 +00:00
parent d4226c934f
commit a3b91bdf42
3 changed files with 40 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2009-01-28 David Chisnall <csdavec@swansea.ac.uk>
* Headers/Foundation/NSEnumerator.h:
* Source/NSEnumerator.m:
Add Apple's fast enumeration protocol.
2009-01-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSException.m: Fix problem preventing stack traccces from

View file

@ -34,7 +34,21 @@
extern "C" {
#endif
@interface NSEnumerator : NSObject
typedef struct
{
unsigned long state;
id *itemsPtr;
unsigned long *mutationsPtr;
unsigned long extra[5];
} NSFastEnumerationState;
@protocol NSFastEnumeration
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *)state
objects: (id *)stackbuf
count: (NSUInteger)len;
@end
@interface NSEnumerator : NSObject <NSFastEnumeration>
- (NSArray *) allObjects;
- (id) nextObject;
@end

View file

@ -74,4 +74,23 @@
return nil;
}
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
objects: (id*)stackbuf
count: (NSUInteger)len
{
IMP nextObject = [self methodForSelector: @selector(nextObject)];
int i;
for (i = 0; i < len; i++)
{
id next = nextObject(self, @selector(nextObject));
if (nil == next)
{
return i;
}
*(stackbuf+i) = next;
}
return len;
}
@end