Permalink
Browse files

simplify setObject:forKey: by using removeObjectForKey: to remove any…

… old mapping rather than trying to be clever by re-using it
  • Loading branch information...
1 parent 0993f6b commit 61b39bdfa63bcae0380b923ce2c948bf6a53945c Michael Ash committed Feb 26, 2012
Showing with 4 additions and 11 deletions.
  1. +4 −11 MAMutableDictionary.m
View
@@ -140,20 +140,13 @@ - (void)removeObjectForKey: (id)key
- (void)setObject: (id)obj forKey: (id)key
{
- NSUInteger bucketIndex = [key hash] % _size;
- _MAMutableDictionaryBucket *bucket = _array[bucketIndex];
- while(bucket)
- {
- if([[bucket key] isEqual: key])
- {
- [bucket setObj: obj];
- return;
- }
- bucket = [bucket next];
- }
_MAMutableDictionaryBucket *newBucket = [[_MAMutableDictionaryBucket alloc] init];
[newBucket setKey: key];
[newBucket setObj: obj];
+
+ [self removeObjectForKey: key];
+
+ NSUInteger bucketIndex = [key hash] % _size;
[newBucket setNext: _array[bucketIndex]];
[_array[bucketIndex] release];
_array[bucketIndex] = newBucket;

0 comments on commit 61b39bd

Please sign in to comment.