ObjFW  Check-in [a5f297053a]

Overview
Comment:Don't allow nil in -[initWithObjectForKey:] and optimize -[description].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a5f297053a42f7153dc56daa46a35da72e74fb80476555bc5acdabacb58aa958
User & Date: js on 2011-04-28 18:03:34
Other Links: manifest | tags
Context
2011-04-28
18:15
Nicer description for empty collections. check-in: d01d9805b3 user: js tags: trunk
18:03
Don't allow nil in -[initWithObjectForKey:] and optimize -[description]. check-in: a5f297053a user: js tags: trunk
2011-04-27
21:29
Fix a typo in -[description] of OFConnectionFailedException. check-in: ffb574eb74 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [188b37a1ab] to [f052320abe].

145
146
147
148
149
150
151




152
153
154
155
156
157
158
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162







+
+
+
+







	  forKey: (id <OFCopying>)key
{
	self = [super init];

	@try {
		uint32_t i;
		struct of_dictionary_bucket *bucket;

		if (key == nil || object == nil)
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		data = [self allocMemoryForNItems: 2
					 withSize: sizeof(*bucket)];

		size = 2;
		for (i = 0; i < size; i++)
			data[i] = NULL;
708
709
710
711
712
713
714
715
716



717
718
719
720
721

722

723
724
725

726
727
728
729
730
731
732
712
713
714
715
716
717
718


719
720
721
722
723
724
725
726
727

728
729
730

731
732
733
734
735
736
737
738







-
-
+
+
+





+
-
+


-
+







	return hash;
}

- (OFString*)description
{
	OFMutableString *ret = [OFMutableString stringWithString: @"{\n"];
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2;
	OFEnumerator *enumerator = [self keyEnumerator];
	id key;
	OFEnumerator *keyEnumerator = [self keyEnumerator];
	OFEnumerator *objectEnumerator = [self objectEnumerator];
	id key, object;
	size_t i;

	i = 0;
	pool2 = [[OFAutoreleasePool alloc] init];

	while ((key = [keyEnumerator nextObject]) != nil &&
	while ((key = [enumerator 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];
	}
	[ret replaceOccurrencesOfString: @"\n"