Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -18,22 +18,21 @@ { unsigned long mutations; } /** - * Sets a key to an object. A key can be any object. + * Sets an object for a key. + * A key can be any object. * * \param key The key to set * \param obj The object to set the key to - * \return The old object, autoreleased */ -- (id)setObject: (OFObject*)obj - forKey: (OFObject *)key; +- (void)setObject: (OFObject*)obj + forKey: (OFObject *)key; /** * Remove the object with the given key from the dictionary. * * \param key The key whose object should be removed - * \return The object that was stored for the key, autoreleased */ -- (id)removeObjectForKey: (OFObject*)key; +- (void)removeObjectForKey: (OFObject*)key; @end Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -77,12 +77,12 @@ [self freeMemory: data]; data = newdata; size = newsize; } -- (id)setObject: (OFObject*)obj - forKey: (OFObject *)key +- (void)setObject: (OFObject*)obj + forKey: (OFObject *)key { uint32_t i, hash, last; id old; if (key == nil || obj == nil) @@ -157,23 +157,21 @@ b->object = obj; b->hash = hash; data[i] = b; count++; - return nil; + return; } old = data[i]->object; data[i]->object = [obj retain]; - - return [old autorelease]; + [old release]; } -- (id)removeObjectForKey: (OFObject*)key +- (void)removeObjectForKey: (OFObject*)key { uint32_t i, hash, last; - id old; if (key == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; @@ -183,50 +181,46 @@ for (i = hash & (size - 1); i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([data[i]->key isEqual: key]) { - old = data[i]->object; - [data[i]->key release]; + [data[i]->object release]; [self freeMemory: data[i]]; data[i] = DELETED; count--; mutations++; [self _resizeForCount: count]; - return [old autorelease]; + return; } } if (i < last) - return nil; + return; /* In case the last bucket is already used */ last = hash & (size - 1); for (i = 0; i < last && data[i] != NULL; i++) { if (data[i] == DELETED) continue; if ([data[i]->key isEqual: key]) { - old = data[i]->object; - [data[i]->key release]; + [data[i]->object release]; [self freeMemory: data[i]]; data[i] = DELETED; count--; mutations++; [self _resizeForCount: count]; - return [old autorelease]; + return; } } - - return nil; } - copy { return [[OFDictionary alloc] initWithDictionary: self]; Index: tests/OFDictionaryTests.m ================================================================== --- tests/OFDictionaryTests.m +++ tests/OFDictionaryTests.m @@ -129,25 +129,26 @@ [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]] && R([dict setObject: @"value3" forKey: @"key3"]) && [[dict objectForKey: @"key3"] isEqual: @"value3"] && - [[dict setObject: @"foo" - forKey: keys[0]] isEqual: values[0]] && + [[dict objectForKey: keys[0]] isEqual: values[0]] && + R([dict setObject: @"foo" + forKey: keys[0]]) && [[dict objectForKey: keys[0]] isEqual: @"foo"]) TEST(@"-[removeObjectForKey:]", - [dict removeObjectForKey: keys[0]] && + R([dict removeObjectForKey: keys[0]]) && [dict objectForKey: keys[0]] == nil) [dict setObject: @"foo" forKey: keys[0]]; TEST(@"-[isEqual:]", ![dict isEqual: dict2] && - [dict removeObjectForKey: @"key3"] && + R([dict removeObjectForKey: @"key3"]) && ![dict isEqual: dict2] && - [dict setObject: values[0] - forKey: keys[0]] && + R([dict setObject: values[0] + forKey: keys[0]]) && [dict isEqual: dict2]) [pool drain]; } @end