ObjFW  Check-in [362d3ed5e8]

Overview
Comment:Don't allow nil in -[initWithObjectForKey:] and optimize -[description].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.5
Files: files | file ages | folders
SHA3-256: 362d3ed5e8e0a861709e190f9e99989303c60b288b18982e37e4698ce3768902
User & Date: js on 2011-04-28 18:03:34
Other Links: branch diff | manifest | tags
Context
2011-06-26
23:40
Check the item size of the passed data array in of_base64_decode(). check-in: 13fe99629c user: js tags: 0.5
2011-04-28
18:15
Nicer description for empty collections. check-in: bbb3994c06 user: js tags: 0.5
18:03
Don't allow nil in -[initWithObjectForKey:] and optimize -[description]. check-in: 362d3ed5e8 user: js tags: 0.5
Changes

Modified src/OFDictionary.m from [beb073a948] to [7dc1c308f0].

144
145
146
147
148
149
150




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







+
+
+
+







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

	@try {
		uint32_t i;
		BUCKET *b;

		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;
704
705
706
707
708
709
710
711
712



713
714
715
716
717

718

719
720
721

722
723
724
725
726
727
728
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
733
734







-
-
+
+
+





+
-
+


-
+







	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"