ObjFW  Check-in [ee77d91252]

Overview
Comment:We can safely assume fast enumeration if we have blocks.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ee77d91252d90e611ba89ccdb38e118ad60b33dd567dd50edef602067044e205
User & Date: js on 2011-09-10 17:36:30
Other Links: manifest | tags
Context
2011-09-10
17:46
Add -[stringByReplacingOccurrencesOfString:withString:]. check-in: a8b61d68ae user: js tags: trunk
17:36
We can safely assume fast enumeration if we have blocks. check-in: ee77d91252 user: js tags: trunk
16:07
Fix a forgotten comment. check-in: 8c8e90bd66 user: js tags: trunk
Changes

Modified src/OFArray.m from [6654434c69] to [7b80c238f7].

538
539
540
541
542
543
544
545
546
547
548
549
550
551

552


553
554



555
556
557
558
559
560
561

- (OFEnumerator*)objectEnumerator
{
	return [[[OFArrayEnumerator alloc] initWithArray: self
					    mutationsPtr: NULL] autorelease];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	size_t i, count = [self count];
	BOOL stop = NO;

	for (i = 0; i < count && !stop; i++)

		block([self objectAtIndex: i], i, &stop);


}




- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
	OFArray *ret;
	size_t count = [self count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];








|


|


|
>
|
>
>
|
|
>
>
>







538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567

- (OFEnumerator*)objectEnumerator
{
	return [[[OFArrayEnumerator alloc] initWithArray: self
					    mutationsPtr: NULL] autorelease];
}

#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION)
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
	size_t i = 0;
	BOOL stop = NO;

	for (id object in self) {
		block(object, i++, &stop);

		if (stop)
			break;
	}
}
#endif

#ifdef OF_HAVE_BLOCKS
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
	OFArray *ret;
	size_t count = [self count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];

Modified src/OFDictionary.m from [7066c6abb0] to [31ff5be5f6].

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

402
403
404



405
406
407
408
409
410
411
			   objects: (id*)objects
			     count: (int)count_
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateKeysAndObjectsUsingBlock:
    (of_dictionary_enumeration_block_t)block
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *enumerator = [self keyEnumerator];
	id key;
	BOOL stop = NO;

	while (!stop && (key = [enumerator nextObject]) != nil)
		block(key, [self objectForKey: key], &stop);


	[pool release];
}




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

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    BOOL *stop) {
		[new setObject: block(key, object)







|



<
<
<


|


>
|
|
|
>
>
>







383
384
385
386
387
388
389
390
391
392
393



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
			   objects: (id*)objects
			     count: (int)count_
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION)
- (void)enumerateKeysAndObjectsUsingBlock:
    (of_dictionary_enumeration_block_t)block
{



	BOOL stop = NO;

	for (id key in self) {
		block(key, [self objectForKey: key], &stop);

		if (stop)
			break;
	}
}
#endif

#ifdef OF_HAVE_BLOCKS
- (OFDictionary*)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block
{
	OFMutableDictionary *new = [OFMutableDictionary dictionary];

	[self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object,
	    BOOL *stop) {
		[new setObject: block(key, object)

Modified src/OFSet.m from [12cfe037e0] to [3e40ae1337].

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

376
377
378



379
380
381
382
383
384
385
	[element retain];
	[pool release];
	[element autorelease];

	return element;
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFEnumerator *enumerator = [self objectEnumerator];
	id object;
	BOOL stop = NO;

	while (!stop && (object = [enumerator nextObject]) != nil)
		block(object, &stop);


	[pool release];
}




- (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block
{
	OFMutableSet *ret = [OFMutableSet set];

	[self enumerateObjectsUsingBlock: ^ (id object, BOOL *stop) {
		if (block(object))
			[ret addObject: object];







|


<
<
<


|


>
|
|
|
>
>
>







358
359
360
361
362
363
364
365
366
367



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
	[element retain];
	[pool release];
	[element autorelease];

	return element;
}

#if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION)
- (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block
{



	BOOL stop = NO;

	for (id object in self) {
		block(object, &stop);

		if (stop)
			break;
	}
}
#endif

#ifdef OF_HAVE_BLOCKS
- (OFSet*)filteredSetUsingBlock: (of_set_filter_block_t)block
{
	OFMutableSet *ret = [OFMutableSet set];

	[self enumerateObjectsUsingBlock: ^ (id object, BOOL *stop) {
		if (block(object))
			[ret addObject: object];