Differences From Artifact [55a42ad5b8]:
- File src/OFArray.m — part of check-in [3e6766ac10] at 2011-07-21 23:56:09 on branch trunk — Add -[enumerateObjectsUsingBlock:] and -[filteredSetUsingBlock:]. (user: js, size: 13920) [annotate] [blame] [check-ins using]
To Artifact [720a88390f]:
- File
src/OFArray.m
— part of check-in
[f9b3ec49f8]
at
2011-07-22 18:49:36
on branch trunk
— Improve methods using blocks in OFArray.
Mutations during enumerations using blocks are now always detected,
even for methods such as -[reduceWithBlock:]. (user: js, size: 13605) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
593 594 595 596 597 598 599 | } [pool release]; } - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { | < < | | < | > | | < < < < < < < < | > | | < | < | < < | < < | | | > > < > | > | | < | < | < < < < < | < | | 593 594 595 596 597 598 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 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | } [pool release]; } - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { tmp[index] = block(object, index); }]; 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 { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { if (block(object, index)) tmp[i++] = object; }]; ret = [OFArray arrayWithCArray: tmp length: i]; } @finally { [self freeMemory: tmp]; } return ret; } - (id)reduceUsingBlock: (of_array_reduce_block_t)block { size_t count = [array count]; __block id current; if (count == 0) return nil; if (count == 1) return [[[self firstObject] retain] autorelease]; [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { id new; if (index == 0) { current = [object retain]; return; } @try { new = [block(current, object) retain]; } @finally { [current release]; } current = new; }]; return [current autorelease]; } #endif - (void)dealloc { |
︙ | ︙ |