ObjFW  Check-in [c52a5e5faf]

Overview
Comment:Fast enumeration improvements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c52a5e5faf44ff566d177ca62c178afbb4b3df0977b3dbe9ea96d8d2d85eb9f2
User & Date: js on 2011-07-19 22:53:55
Other Links: manifest | tags
Context
2011-07-19
23:04
Add fast enumeration to OFSet. check-in: cbf0b4dd91 user: js tags: trunk
22:53
Fast enumeration improvements. check-in: c52a5e5faf user: js tags: trunk
2011-07-18
23:47
Fix a bug (hopefully the last!) in blocks. check-in: b330936afe user: js tags: trunk
Changes

Modified src/OFEnumerator.h from [992da1f406] to [bd16795e9a].

64
65
66
67
68
69
70

71


72
73
74
75
76
77
78
	/// Arbitrary state information for the enumeration
	unsigned long state;
	/// Pointer to a C array of objects to return
	id *itemsPtr;
	/// Arbitrary state information to detect mutations
	unsigned long *mutationsPtr;
	/// Additional arbitrary state information

	unsigned long extra[5];


} of_fast_enumeration_state_t;
#endif

/**
 * \brief A protocol for fast enumeration.
 *
 * The OFFastEnumeration protocol needs to be implemented by all classes







>
|
>
>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
	/// Arbitrary state information for the enumeration
	unsigned long state;
	/// Pointer to a C array of objects to return
	id *itemsPtr;
	/// Arbitrary state information to detect mutations
	unsigned long *mutationsPtr;
	/// Additional arbitrary state information
	union {
		unsigned long longs[5];
		void *pointers[2];
	} extra;
} of_fast_enumeration_state_t;
#endif

/**
 * \brief A protocol for fast enumeration.
 *
 * The OFFastEnumeration protocol needs to be implemented by all classes

Modified src/OFList.m from [ba2a81b1ec] to [e971f4ddef].

390
391
392
393
394
395
396
397

398
399
400
401
402
403
404
405
406

407

408
409
410

411




412
413
414
415
416
417
418
419
	return element;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	of_list_object_t **listObject = (of_list_object_t**)state->extra;


	state->itemsPtr = objects;
	state->mutationsPtr = &mutations;

	if (state->state == 0) {
		*listObject = firstListObject;
		state->state = 1;
	}


	if (*listObject == NULL)

		return 0;

	objects[0] = (*listObject)->object;

	*listObject = (*listObject)->next;




	return 1;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFListEnumerator alloc]
		initWithList: self
	    mutationsPointer: &mutations] autorelease];







|
>





|



>
|
>
|
|
|
>
|
>
>
>
>
|







390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
	return element;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	of_list_object_t *listObject = state->extra.pointers[0];
	int i;

	state->itemsPtr = objects;
	state->mutationsPtr = &mutations;

	if (state->state == 0) {
		listObject = firstListObject;
		state->state = 1;
	}

	for (i = 0; i < count_; i++) {
		if (listObject == NULL) {
			state->extra.pointers[0] = NULL;
			return i;
		}

		objects[i] = listObject->object;
		listObject = listObject->next;
	}

	state->extra.pointers[0] = listObject;

	return count_;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFListEnumerator alloc]
		initWithList: self
	    mutationsPointer: &mutations] autorelease];