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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
initWithDataArray: array
mutationsPointer: NULL] autorelease];
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
id *objs = [array cArray];
size_t i, count = [array count];
BOOL stop = NO;
for (i = 0; i < count && !stop; i++)
block(objs[i], i, &stop);
}
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
OFArray *ret;
size_t count = [array count];
id *tmp = [self allocMemoryForNItems: count
withSize: sizeof(id)];
@try {
id *objs = [array cArray];
size_t i;
for (i = 0; i < count; i++)
tmp[i] = block(objs[i], i);
ret = [OFArray arrayWithCArray: tmp
length: count];
} @finally {
[self freeMemory: tmp];
}
return ret;
}
- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{
OFArray *ret;
size_t count = [array count];
id *tmp = [self allocMemoryForNItems: count
withSize: sizeof(id)];
@try {
id *objs = [array cArray];
size_t i, j = 0;
for (i = 0; i < count; i++)
if (block(objs[i], i))
tmp[j++] = objs[i];
ret = [OFArray arrayWithCArray: tmp
length: j];
} @finally {
[self freeMemory: tmp];
}
|
>
|
>
>
>
>
>
|
|
>
>
>
>
>
>
>
|
>
>
>
>
>
|
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
initWithDataArray: array
mutationsPointer: NULL] autorelease];
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
id *objs = [array cArray];
size_t i, count = [array count];
BOOL stop = NO;
for (i = 0; i < count && !stop; i++) {
block(objs[i], i, &stop);
[pool releaseObjects];
}
[pool release];
}
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFArray *ret;
size_t count = [array count];
id *tmp = [self allocMemoryForNItems: count
withSize: sizeof(id)];
@try {
id *objs = [array cArray];
size_t i;
for (i = 0; i < count; i++)
tmp[i] = block(objs[i], i);
ret = [[OFArray alloc] initWithCArray: tmp
length: count];
@try {
[pool release];
} @finally {
[ret autorelease];
}
} @finally {
[self freeMemory: tmp];
}
return ret;
}
- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFArray *ret;
size_t count = [array count];
id *tmp = [self allocMemoryForNItems: count
withSize: sizeof(id)];
@try {
id *objs = [array cArray];
size_t i, j = 0;
for (i = 0; i < count; i++) {
if (block(objs[i], i))
tmp[j++] = objs[i];
[pool releaseObjects];
}
[pool release];
ret = [OFArray arrayWithCArray: tmp
length: j];
} @finally {
[self freeMemory: tmp];
}
|