ObjFW  Check-in [8823a4df67]

Overview
Comment:Add -[OFMutableSet removeAllObjects]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8823a4df67ec1c7128fe105ee9cb970bcee09d81f3ae0ff42bf88ff3a177b0a4
User & Date: js on 2017-08-19 08:24:40
Other Links: manifest | tags
Context
2017-08-19
09:19
OFZIPArchive: Fix ZIP64Index not being set check-in: 1f4407ddf1 user: js tags: trunk
08:24
Add -[OFMutableSet removeAllObjects] check-in: 8823a4df67 user: js tags: trunk
2017-08-14
13:33
Always have assign before nonatomic check-in: 4eab54022e user: js tags: trunk
Changes

Modified src/OFCountedSet.m from [08a16819c3] to [917f8ad622].

260
261
262
263
264
265
266















267
268
269
270

			for (size_t i = 0; i < count; i++)
				[self addObject: object];
		}
	} else
		for (id object in set)
			[self addObject: object];
















	objc_autoreleasePoolPop(pool);
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

			for (size_t i = 0; i < count; i++)
				[self addObject: object];
		}
	} else
		for (id object in set)
			[self addObject: object];

	objc_autoreleasePoolPop(pool);
}

- (void)removeAllObjects
{
	void *pool = objc_autoreleasePoolPush();
	OFSet *copy = [[self copy] autorelease];

	for (id object in copy) {
		size_t count = [self countForObject: object];

		for (size_t i = 0; i < count; i++)
			[self removeObject: object];
	}

	objc_autoreleasePoolPop(pool);
}
@end

Modified src/OFCountedSet_hashtable.m from [b91174aa25] to [0205b4710b].

206
207
208
209
210
211
212





213
214
215
216
217

	if (count > 0)
		[_mapTable setObject: (void *)(uintptr_t)count
			      forKey: object];
	else
		[_mapTable removeObjectForKey: object];
}






- (void)makeImmutable
{
}
@end







>
>
>
>
>





206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

	if (count > 0)
		[_mapTable setObject: (void *)(uintptr_t)count
			      forKey: object];
	else
		[_mapTable removeObjectForKey: object];
}

- (void)removeAllObjects
{
	[_mapTable removeAllObjects];
}

- (void)makeImmutable
{
}
@end

Modified src/OFMutableSet.h from [e778a4929f] to [e31e233b6e].

77
78
79
80
81
82
83





84
85
86
87
88
89
90
91
92
93
/*!
 * @brief Creates a union of the receiver and the specified set.
 *
 * @param set The set to create the union with
 */
- (void)unionSet: (OFSet OF_GENERIC(ObjectType) *)set;






/*!
 * @brief Converts the mutable set to an immutable set.
 */
- (void)makeImmutable;
#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
# undef ObjectType
#endif
@end

OF_ASSUME_NONNULL_END







>
>
>
>
>










77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*!
 * @brief Creates a union of the receiver and the specified set.
 *
 * @param set The set to create the union with
 */
- (void)unionSet: (OFSet OF_GENERIC(ObjectType) *)set;

/*!
 * @brief Removes all objects from the set.
 */
- (void)removeAllObjects;

/*!
 * @brief Converts the mutable set to an immutable set.
 */
- (void)makeImmutable;
#if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN)
# undef ObjectType
#endif
@end

OF_ASSUME_NONNULL_END

Modified src/OFMutableSet.m from [be0ab30e62] to [c759b99c57].

189
190
191
192
193
194
195











196
197
198
199
200
}

- (void)unionSet: (OFSet *)set
{
	for (id object in set)
		[self addObject: object];
}












- (void)makeImmutable
{
}
@end







>
>
>
>
>
>
>
>
>
>
>





189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
}

- (void)unionSet: (OFSet *)set
{
	for (id object in set)
		[self addObject: object];
}

- (void)removeAllObjects
{
	void *pool = objc_autoreleasePoolPush();
	OFSet *copy = [[self copy] autorelease];

	for (id object in copy)
		[self removeObject: object];

	objc_autoreleasePoolPop(pool);
}

- (void)makeImmutable
{
}
@end

Modified src/OFMutableSet_hashtable.m from [6a9e638b4e] to [b88d2a251a].

33
34
35
36
37
38
39





40
41
42
43
44
45
		      forKey: object];
}

- (void)removeObject: (id)object
{
	[_mapTable removeObjectForKey: object];
}






- (void)makeImmutable
{
	object_setClass(self, [OFSet_hashtable class]);
}
@end







>
>
>
>
>






33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
		      forKey: object];
}

- (void)removeObject: (id)object
{
	[_mapTable removeObjectForKey: object];
}

- (void)removeAllObjects
{
	[_mapTable removeAllObjects];
}

- (void)makeImmutable
{
	object_setClass(self, [OFSet_hashtable class]);
}
@end

Modified tests/OFSetTests.m from [104e780811] to [601d8ce9b6].

86
87
88
89
90
91
92




93
94
95
96
97
98
99
	    nil]])

	TEST(@"-[unionSet:]",
	    R([mutableSet unionSet: [OFSet setWithObjects: @"x", @"bar",
	    nil]]) && [mutableSet isEqual: [OFSet setWithObjects: @"baz",
	    @"bar", @"x", nil]])





	ok = true;
	i = 0;

	for (OFString *s in set1) {
		switch (i) {
		case 0:
			if (![s isEqual: @"x"])







>
>
>
>







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	    nil]])

	TEST(@"-[unionSet:]",
	    R([mutableSet unionSet: [OFSet setWithObjects: @"x", @"bar",
	    nil]]) && [mutableSet isEqual: [OFSet setWithObjects: @"baz",
	    @"bar", @"x", nil]])

	TEST(@"-[removeAllObjects]",
	    R([mutableSet removeAllObjects]) &&
	    [mutableSet isEqual: [OFSet set]])

	ok = true;
	i = 0;

	for (OFString *s in set1) {
		switch (i) {
		case 0:
			if (![s isEqual: @"x"])
118
119
120
121
122
123
124


125
126
127
128
129
130
131

	if (i != 4)
		ok = false;

	TEST(@"Fast enumeration", ok)

	ok = false;


	@try {
		for (OFString *s in mutableSet)
			[mutableSet removeObject: s];
	} @catch (OFEnumerationMutationException *e) {
		ok = true;
	}








>
>







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

	if (i != 4)
		ok = false;

	TEST(@"Fast enumeration", ok)

	ok = false;
	[mutableSet addObject: @"foo"];
	[mutableSet addObject: @"bar"];
	@try {
		for (OFString *s in mutableSet)
			[mutableSet removeObject: s];
	} @catch (OFEnumerationMutationException *e) {
		ok = true;
	}