mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
NSPointerArray: Implement NSFastEnumeration
This commit is contained in:
parent
4a4a802060
commit
b993f10e76
2 changed files with 29 additions and 1 deletions
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
* or grow (adding nil/zero items).
|
||||
*/
|
||||
GS_EXPORT_CLASS
|
||||
@interface NSPointerArray : NSObject <NSCopying, NSCoding>
|
||||
@interface NSPointerArray : NSObject <NSCoding, NSCopying, NSFastEnumeration>
|
||||
|
||||
/** Allocate an instance, initialise using initWithOptions: and
|
||||
* return it autoreleased.
|
||||
|
|
|
@ -197,6 +197,34 @@ static Class concreteClass = Nil;
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
||||
objects: (__unsafe_unretained id[])stackbuf
|
||||
count: (NSUInteger)len
|
||||
{
|
||||
NSInteger count;
|
||||
|
||||
state->mutationsPtr = (unsigned long *)&state->mutationsPtr;
|
||||
count = MIN(len, [self count] - state->state);
|
||||
if (count > 0)
|
||||
{
|
||||
IMP imp = [self methodForSelector: @selector(pointerAtIndex:)];
|
||||
int p = state->state;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++, p++)
|
||||
{
|
||||
stackbuf[i] = (*imp)(self, @selector(pointerAtIndex:), p);
|
||||
}
|
||||
state->state += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
state->itemsPtr = stackbuf;
|
||||
return count;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSPointerArray (NSArrayConveniences)
|
||||
|
|
Loading…
Reference in a new issue