@@ -36,10 +36,11 @@ @end @interface SimpleMutableDictionary: OFMutableDictionary { OFMutableDictionary *_dictionary; + unsigned long _mutations; } @end @implementation SimpleDictionary - (instancetype)init @@ -111,24 +112,10 @@ - (OFEnumerator *)keyEnumerator { return [_dictionary keyEnumerator]; } - -- (OFEnumerator *)objectEnumerator -{ - return [_dictionary objectEnumerator]; -} - -- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state - objects: (id *)objects - count: (int)count -{ - return [_dictionary countByEnumeratingWithState: state - objects: objects - count: count]; -} @end @implementation SimpleMutableDictionary + (void)initialize { @@ -137,17 +124,40 @@ } - (void)setObject: (id)object forKey: (id)key { + bool existed = ([_dictionary objectForKey: key] == nil); + [_dictionary setObject: object forKey: key]; + + if (existed) + _mutations++; } - (void)removeObjectForKey: (id)key { + bool existed = ([_dictionary objectForKey: key] == nil); + [_dictionary removeObjectForKey: key]; + + if (existed) + _mutations++; +} + +- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state + objects: (id *)objects + count: (int)count +{ + int ret = [super countByEnumeratingWithState: state + objects: objects + count: count]; + + state->mutationsPtr = &_mutations; + + return ret; } @end @implementation TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTestsWithClass: (Class)dictionaryClass