ObjFW  Check-in [bff98a6244]

Overview
Comment:Simplify -[OFDictionary all{Keys,Objects}].

This is possible now since +[OFArray arrayWithCapacity:] has been added.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bff98a624480f19d6ac2da683fbd3bf093bf68ea66e39cdcbdcb26719ad70e40
User & Date: js on 2013-04-09 21:37:13
Other Links: manifest | tags
Context
2013-04-09
22:09
Fix incomplete of_char16_t migration. check-in: 8fe08864f8 user: js tags: trunk
21:37
Simplify -[OFDictionary all{Keys,Objects}]. check-in: bff98a6244 user: js tags: trunk
21:35
Add -[OFEnumerator allObjects]. check-in: 7f0e327251 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [b5ab4c9ae4] to [ff91f774b0].

407
408
409
410
411
412
413

414
415
416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
434
435
436
437
438
439
440
441

442
443
444
445
446
447
448
449
450
451
452
453
454

455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
	objc_autoreleasePoolPop(pool);

	return false;
}

- (OFArray*)allKeys
{

	void *pool = objc_autoreleasePoolPush();
	id *keys = [self allocMemoryWithSize: sizeof(id)
				       count: [self count]];
	OFArray *ret;
	OFEnumerator *enumerator;
	id key;
	size_t i = 0;

	enumerator = [self keyEnumerator];
	while ((key = [enumerator nextObject]) != nil)
		keys[i++] = key;

	assert(i == [self count]);


	objc_autoreleasePoolPop(pool);

	@try {
		ret = [OFArray arrayWithObjects: keys
					  count: [self count]];
	} @finally {
		[self freeMemory: keys];
	}

	return ret;
}

- (OFArray*)allObjects
{

	void *pool = objc_autoreleasePoolPush();
	id *objects = [self allocMemoryWithSize: sizeof(id)
					  count: [self count]];
	OFArray *ret;
	OFEnumerator *enumerator;
	id object;
	size_t i = 0;

	enumerator = [self objectEnumerator];
	while ((object = [enumerator nextObject]) != nil)
		objects[i++] = object;

	assert(i == [self count]);


	objc_autoreleasePoolPop(pool);

	@try {
		ret = [OFArray arrayWithObjects: objects
					  count: [self count]];
	} @finally {
		[self freeMemory: objects];
	}

	return ret;
}

- (OFEnumerator*)objectEnumerator
{
	[self doesNotRecognizeSelector: _cmd];
	abort();







>

<
<
<
|

<

<

|

<
>



<
<
<
<
<
<
<





>

<
<
<
|

<

<

|

<
>



<
<
<
<
<
<
<







407
408
409
410
411
412
413
414
415



416
417

418

419
420
421

422
423
424
425







426
427
428
429
430
431
432



433
434

435

436
437
438

439
440
441
442







443
444
445
446
447
448
449
	objc_autoreleasePoolPop(pool);

	return false;
}

- (OFArray*)allKeys
{
	OFMutableArray *ret = [OFMutableArray arrayWithCapacity: [self count]];
	void *pool = objc_autoreleasePoolPush();



	OFEnumerator *enumerator = [self keyEnumerator];
	id key;



	while ((key = [enumerator nextObject]) != nil)
		[ret addObject: key];


	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);








	return ret;
}

- (OFArray*)allObjects
{
	OFMutableArray *ret = [OFMutableArray arrayWithCapacity: [self count]];
	void *pool = objc_autoreleasePoolPush();



	OFEnumerator *enumerator = [self objectEnumerator];
	id object;



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


	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);








	return ret;
}

- (OFEnumerator*)objectEnumerator
{
	[self doesNotRecognizeSelector: _cmd];
	abort();