Differences From Artifact [5ae87127d9]:
- File
src/OFArray.m
— part of check-in
[f7576a66ce]
at
2012-06-06 13:47:52
on branch trunk
— Slightly change the memory management API.
Also fix a bug where OFBigDataArray would waste memory. (user: js, size: 13903) [annotate] [blame] [check-ins using] [more...]
To Artifact [7b45e24981]:
- File
src/OFArray.m
— part of check-in
[95e8e1e486]
at
2012-06-10 16:03:01
on branch trunk
— Add a few array methods.
OFArray:
* +[arrayByAddingObject:]
* +[arrayByAddingObjectsFromArray:]OFMutableArray:
* -[addObjectsFromArray:]
* -[insertObjectsFromArray:atIndex:] (user: js, size: 14254) [annotate] [blame] [check-ins using] [more...]
| ︙ | ︙ | |||
242 243 244 245 246 247 248 |
{
OFObject *container;
size_t count;
id *buffer;
container = [[[OFObject alloc] init] autorelease];
count = [self count];
| | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
{
OFObject *container;
size_t count;
id *buffer;
container = [[[OFObject alloc] init] autorelease];
count = [self count];
buffer = [container allocMemoryWithSize: sizeof(*buffer)
count: [self count]];
[self getObjects: buffer
inRange: of_range(0, count)];
return buffer;
}
|
| ︙ | ︙ | |||
331 332 333 334 335 336 337 | OFArray *ret; id *buffer; if (![self isKindOfClass: [OFMutableArray class]]) return [OFArray_subarray arrayWithArray: self range: range]; | | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
OFArray *ret;
id *buffer;
if (![self isKindOfClass: [OFMutableArray class]])
return [OFArray_subarray arrayWithArray: self
range: range];
buffer = [self allocMemoryWithSize: sizeof(*buffer)
count: range.length];
@try {
[self getObjects: buffer
inRange: range];
ret = [OFArray arrayWithObjects: buffer
count: range.length];
|
| ︙ | ︙ | |||
599 600 601 602 603 604 605 606 607 608 609 610 611 |
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];
| > > > > > > > > > > > > > > > > > > > > | | | | | 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
block(object, i++, &stop);
if (stop)
break;
}
}
#endif
- (OFArray*)arrayByAddingObject: (id)object
{
OFMutableArray *ret = [[self mutableCopy] autorelease];
[ret addObject: object];
[ret makeImmutable];
return ret;
}
- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array
{
OFMutableArray *ret = [[self mutableCopy] autorelease];
[ret addObjectsFromArray: array];
[ret makeImmutable];
return ret;
}
#ifdef OF_HAVE_BLOCKS
- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
OFArray *ret;
size_t count = [self count];
id *tmp = [self allocMemoryWithSize: sizeof(id)
count: count];
@try {
[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
BOOL *stop) {
tmp[index] = block(object, index);
}];
ret = [OFArray arrayWithObjects: tmp
count: count];
} @finally {
[self freeMemory: tmp];
}
return ret;
}
- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{
OFArray *ret;
size_t count = [self count];
id *tmp = [self allocMemoryWithSize: sizeof(id)
count: count];
@try {
__block size_t i = 0;
[self enumerateObjectsUsingBlock: ^ (id object, size_t index,
BOOL *stop) {
if (block(object, index))
|
| ︙ | ︙ |