@@ -34,11 +34,11 @@ #define BUCKET struct of_dictionary_bucket #define DELETED &of_dictionary_deleted_bucket @implementation OFDictionary -+ dictionary; ++ dictionary { return [[[self alloc] init] autorelease]; } + dictionaryWithDictionary: (OFDictionary*)dict @@ -146,10 +146,14 @@ self = [super init]; @try { uint32_t i; BUCKET *b; + + if (key == nil || obj == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; data = [self allocMemoryForNItems: 2 withSize: sizeof(BUCKET*)]; size = 2; @@ -453,10 +457,11 @@ [obj release]; @throw e; } data[j]->object = obj; + count--; } } @catch (id e) { [self release]; @throw e; } @@ -703,23 +708,33 @@ return hash; } - (OFString*)description { - OFMutableString *ret = [OFMutableString stringWithString: @"{\n"]; - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; - OFEnumerator *enumerator = [self keyEnumerator]; - id key; + OFMutableString *ret; + OFAutoreleasePool *pool, *pool2; + OFEnumerator *keyEnumerator; + OFEnumerator *objectEnumerator; + id key, object; size_t i; + if (count == 0) + return @"{}"; + + ret = [OFMutableString stringWithString: @"{\n"]; + pool = [[OFAutoreleasePool alloc] init]; + keyEnumerator = [self keyEnumerator]; + objectEnumerator = [self objectEnumerator]; + i = 0; pool2 = [[OFAutoreleasePool alloc] init]; - while ((key = [enumerator nextObject]) != nil) { + while ((key = [keyEnumerator nextObject]) != nil && + (object = [objectEnumerator nextObject]) != nil) { [ret appendString: [key description]]; [ret appendString: @" = "]; - [ret appendString: [[self objectForKey: key] description]]; + [ret appendString: [object description]]; if (++i < count) [ret appendString: @";\n"]; [pool2 releaseObjects];