@@ -77,14 +77,15 @@ [self freeMemory: data]; data = newdata; size = newsize; } -- setObject: (OFObject*)obj - forKey: (OFObject *)key +- (id)setObject: (OFObject*)obj + forKey: (OFObject *)key { uint32_t i, hash, last; + id old; if (key == nil || obj == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; @@ -156,23 +157,23 @@ b->object = obj; b->hash = hash; data[i] = b; count++; - return self; + return nil; } - [obj retain]; - [data[i]->object release]; - data[i]->object = obj; + old = data[i]->object; + data[i]->object = [obj retain]; - return self; + return [old autorelease]; } -- removeObjectForKey: (OFObject*)key +- (id)removeObjectForKey: (OFObject*)key { uint32_t i, hash, last; + id old; if (key == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; @@ -182,48 +183,50 @@ 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 self; + return [old autorelease]; } } if (i < last) - return self; + return nil; /* 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 self; + return [old autorelease]; } } - return self; + return nil; } - (id)copy { return [[OFDictionary alloc] initWithDictionary: self];