@@ -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