Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -253,11 +253,44 @@ - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state objects: (id *)objects count: (int)count { - OF_UNRECOGNIZED_SELECTOR + OFEnumerator *enumerator; + int i; + + memcpy(&enumerator, state->extra, sizeof(enumerator)); + + if (enumerator == nil) { + void *pool = objc_autoreleasePoolPush(); + + enumerator = [[self objectEnumerator] retain]; + memcpy(state->extra, &enumerator, sizeof(enumerator)); + + objc_autoreleasePoolPop(pool); + } + + state->itemsPtr = objects; + state->mutationsPtr = (unsigned long *)self; + + if (state->state == 1) + return 0; + + for (i = 0; i < count; i++) { + id object = [enumerator nextObject]; + + if (object == nil) { + state->state = 1; + [enumerator release]; + + return i; + } + + objects[i] = object; + } + + return i; } - (bool)isEqual: (id)object { OFSet *set; Index: tests/OFSetTests.m ================================================================== --- tests/OFSetTests.m +++ tests/OFSetTests.m @@ -32,10 +32,11 @@ @end @interface SimpleMutableSet: OFMutableSet { OFMutableSet *_set; + unsigned long _mutations; } @end @implementation SimpleSet - (instancetype)init @@ -115,19 +116,10 @@ - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } - -- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state - objects: (id *)objects - count: (int)count -{ - return [_set countByEnumeratingWithState: state - objects: objects - count: count]; -} @end @implementation SimpleMutableSet + (void)initialize { @@ -135,16 +127,39 @@ [self inheritMethodsFromClass: [SimpleSet class]]; } - (void)addObject: (id)object { + bool existed = [self containsObject: object]; + [_set addObject: object]; + + if (existed) + _mutations++; } - (void)removeObject: (id)object { + bool existed = [self containsObject: object]; + [_set removeObject: object]; + + if (existed) + _mutations++; +} + +- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state + objects: (id *)objects + count: (int)count +{ + int ret = [_set countByEnumeratingWithState: state + objects: objects + count: count]; + + state->mutationsPtr = &_mutations; + + return ret; } @end @implementation TestsAppDelegate (OFSetTests) - (void)setTestsWithClass: (Class)setClass