ObjFW  Check-in [e287e086c2]

Overview
Comment:Nicer fast enumeration for OFSet.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e287e086c269dddfe03a6caeaf1a95ab065c744106cc3e86b02362c477e9e7dc
User & Date: js on 2011-07-22 18:30:50
Other Links: manifest | tags
Context
2011-07-22
18:49
Improve methods using blocks in OFArray. check-in: f9b3ec49f8 user: js tags: trunk
18:30
Nicer fast enumeration for OFSet. check-in: e287e086c2 user: js tags: trunk
00:00
Include OFSet in ObjFW.h. check-in: ac598c5ec3 user: js tags: trunk
Changes

Modified src/OFMutableSet.m from [77a980e945] to [842dbccb4e].

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	id object;

	while ((object = [enumerator nextObject]) != nil)
		[self addObject: object];

	[pool release];
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{
	int ret = [super countByEnumeratingWithState: state
					     objects: objects
					       count: count];

	state->mutationsPtr = &mutations;

	return ret;
}
@end







<
<
<
<
<
<
<
<
<
<
<
<
<

75
76
77
78
79
80
81













82
	id object;

	while ((object = [enumerator nextObject]) != nil)
		[self addObject: object];

	[pool release];
}













@end

Modified src/OFSet.m from [89818a2387] to [055b4111d5].

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
	return [dictionary keyEnumerator];
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{
	OFAutoreleasePool *pool = state->extra.pointers[0];
	OFEnumerator *enumerator = state->extra.pointers[1];
	int i;

	state->itemsPtr = objects;
	state->mutationsPtr = (unsigned long*)self;

	if (state->state == -1)
		return 0;

	if (state->state == 0) {
		pool = [[OFAutoreleasePool alloc] init];
		enumerator = [dictionary keyEnumerator];

		state->extra.pointers[0] = pool;
		state->extra.pointers[1] = enumerator;

		state->state = 1;
	}

	for (i = 0; i < count; i++) {
		id object = [enumerator nextObject];

		if (object == nil) {
			[pool release];
			state->state = -1;
			return i;
		}

		objects[i] = object;
	}

	return count;
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block
{
	[dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    BOOL *stop) {







<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







269
270
271
272
273
274
275



276
277



























278
279
280
281
282
283
284
285
	return [dictionary keyEnumerator];
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count
{



	return [dictionary countByEnumeratingWithState: state
					       objects: objects



























						 count: count];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block
{
	[dictionary enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    BOOL *stop) {