@@ -116,11 +116,11 @@ - initWithKey: (OFObject *)key andObject: (OFObject*)obj { Class c; - uint32_t hash; + uint32_t fullhash, hash; self = [self init]; if (key == nil || obj == nil) { c = isa; @@ -127,29 +127,33 @@ [self dealloc]; @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; } - hash = [key hash] & (size - 1); + fullhash = [key hash]; + hash = fullhash & (size - 1); @try { key = [key copy]; } @catch (OFException *e) { [self dealloc]; @throw e; } @try { - data[hash] = [[OFList alloc] init]; + of_dictionary_list_object_t *o; + + data[hash] = [[OFList alloc] initWithListObjectSize: + sizeof(of_dictionary_list_object_t)]; - [data[hash] append: key]; - [data[hash] append: obj]; + o = (of_dictionary_list_object_t*)[data[hash] append: obj]; + o->key = key; + o->hash = fullhash; } @catch (OFException *e) { + [key release]; [self dealloc]; @throw e; - } @finally { - [key release]; } return self; } @@ -173,40 +177,46 @@ keys_data = [keys data]; objs_data = [objs data]; for (i = 0; i < count; i++) { - uint32_t hash; + uint32_t fullhash, hash; OFObject *key; if (keys_data[i] == nil || objs_data[i] == nil) { c = isa; [self dealloc]; @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; } - hash = [keys_data[i] hash] & (size - 1); + fullhash = [keys_data[i] hash]; + hash = fullhash & (size - 1); @try { key = [keys_data[i] copy]; } @catch (OFException *e) { [self dealloc]; @throw e; } @try { + of_dictionary_list_object_t *o; + if (data[hash] == nil) - data[hash] = [[OFList alloc] init]; + data[hash] = [[OFList alloc] + initWithListObjectSize: + sizeof(of_dictionary_list_object_t)]; - [data[hash] append: key]; - [data[hash] append: objs_data[i]]; + o = (of_dictionary_list_object_t*) + [data[hash] append: objs_data[i]]; + o->key = key; + o->hash = fullhash; } @catch (OFException *e) { + [key release]; [self dealloc]; @throw e; - } @finally { - [key release]; } } return self; } @@ -228,11 +238,11 @@ andArgList: (va_list)args { OFObject *key; OFObject *obj; Class c; - uint32_t hash; + uint32_t fullhash, hash; self = [self init]; obj = va_arg(args, OFObject*); if (first == nil || obj == nil) { @@ -240,30 +250,34 @@ [self dealloc]; @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; } - hash = [first hash] & (size - 1); + fullhash = [first hash]; + hash = fullhash & (size - 1); @try { key = [first copy]; } @catch (OFException *e) { [self dealloc]; @throw e; } @try { + of_dictionary_list_object_t *o; + if (data[hash] == nil) - data[hash] = [[OFList alloc] init]; + data[hash] = [[OFList alloc] initWithListObjectSize: + sizeof(of_dictionary_list_object_t)]; - [data[hash] append: key]; - [data[hash] append: obj]; + o = (of_dictionary_list_object_t*)[data[hash] append: obj]; + o->key = key; + o->hash = fullhash; } @catch (OFException *e) { + [key release]; [self dealloc]; @throw e; - } @finally { - [key release]; } while ((key = va_arg(args, OFObject *)) != nil) { if ((obj = va_arg(args, OFObject*)) == nil) { c = isa; @@ -270,30 +284,36 @@ [self dealloc]; @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; } - hash = [key hash] & (size - 1); + fullhash = [key hash]; + hash = fullhash & (size - 1); @try { key = [key copy]; } @catch (OFException *e) { [self dealloc]; @throw e; } @try { + of_dictionary_list_object_t *o; + if (data[hash] == nil) - data[hash] = [[OFList alloc] init]; + data[hash] = [[OFList alloc] + initWithListObjectSize: + sizeof(of_dictionary_list_object_t)]; - [data[hash] append: key]; - [data[hash] append: obj]; + o = (of_dictionary_list_object_t*) + [data[hash] append: obj]; + o->key = key; + o->hash = fullhash; } @catch (OFException *e) { + [key release]; [self dealloc]; @throw e; - } @finally { - [key release]; } } return self; } @@ -305,11 +325,11 @@ items = 0; buckets = 0; for (i = 0; i < size; i++) { if (data[i] != nil) { - items += [data[i] count] / 2; + items += [data[i] count]; buckets++; } } return (float)items / buckets; @@ -316,11 +336,11 @@ } - (id)objectForKey: (OFObject*)key { uint32_t hash; - of_list_object_t *iter; + of_dictionary_list_object_t *iter; if (key == nil) @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; @@ -327,13 +347,14 @@ hash = [key hash] & (size - 1); if (data[hash] == nil) return nil; - for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) - if ([iter->object isEqual: key]) - return iter->next->object; + for (iter = (of_dictionary_list_object_t*)[data[hash] first]; + iter != NULL; iter = iter->next) + if ([iter->key isEqual: key]) + return iter->object; return nil; } /* FIXME: Implement this! */ @@ -353,13 +374,21 @@ - (void)dealloc { size_t i; - for (i = 0; i < size; i++) - if (data[i] != nil) + for (i = 0; i < size; i++) { + if (data[i] != nil) { + of_dictionary_list_object_t *iter; + + for (iter = (of_dictionary_list_object_t*) + [data[i] first]; iter != NULL; iter = iter->next) + [iter->key release]; + [data[i] release]; + } + } [super dealloc]; } - setObject: (OFObject*)obj