mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
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:
parent
d4226c934f
commit
a3b91bdf42
3 changed files with 40 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue