ObjFW  Check-in [6214a3be25]

Overview
Comment:Improve methods using blocks in OFDictionary.

Mutations during enumerations using blocks are now always detected,
even for methods such as -[filteredDictionaryUsingBlock:].

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6214a3be25ee7692d661996f59b326106f4a9d388585cf104eaef9cfcc66b5cf
User & Date: js on 2011-07-22 17:03:22
Other Links: manifest | tags
Context
2011-07-22
18:59
Rename object1 and object2 to left and right in -[reduceWithBlock:]. check-in: 030cc6df0e user: js tags: trunk
17:09
Rename -[reduceUsingBlock:] to -[foldUsingBlock:]. check-in: d6faaf68b9 user: js tags: trunk
17:03
Improve methods using blocks in OFDictionary. check-in: 6214a3be25 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [b5e17c6561] to [95bb1cf3d0].

747
748
749
750
751
752
753
754
755

756

757
758
759



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775

776

777
778
779
780




781
782
783
784
785
786
787
747
748
749
750
751
752
753

754
755

756



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

774
775

776




777
778
779
780
781
782
783
784
785
786
787







-

+
-
+
-
-
-
+
+
+














-

+
-
+
-
-
-
-
+
+
+
+








	[pool release];
}

- (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block
{
	OFMutableDictionary *new = [OFMutableDictionary dictionary];
	size_t i;

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	for (i = 0; i < size; i++)
	    BOOL *stop) {
		if (data[i] != NULL && data[i] != DELETED)
			[new setObject: block(data[i]->key, data[i]->object)
				forKey: data[i]->key];
		[new setObject: block(key, object)
			forKey: key];
	}];

	/*
	 * Class swizzle the dictionary to be immutable. We declared the return
	 * type to be OFDictionary*, so it can't be modified anyway. But not
	 * swizzling it would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFDictionary class];
	return new;
}

- (OFDictionary*)filteredDictionaryUsingBlock:
    (of_dictionary_filter_block_t)block
{
	OFMutableDictionary *new = [OFMutableDictionary dictionary];
	size_t i;

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	for (i = 0; i < size; i++)
	    BOOL *stop) {
		if (data[i] != NULL && data[i] != DELETED)
			if (block(data[i]->key, data[i]->object))
				[new setObject: data[i]->object
					forKey: data[i]->key];
		if (block(key, object))
			[new setObject: object
				forKey: key];
	}];

	/*
	 * Class swizzle the dictionary to be immutable. We declared the return
	 * type to be OFDictionary*, so it can't be modified anyway. But not
	 * swizzling it would create a real copy each time -[copy] is called.
	 */
	new->isa = [OFDictionary class];