Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -595,101 +595,81 @@ [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 *cArray = [array cArray]; - size_t i; - - for (i = 0; i < count; i++) - tmp[i] = block(cArray[i], i); - - ret = [[OFArray alloc] initWithCArray: tmp - length: count]; - - @try { - [pool release]; - } @finally { - [ret autorelease]; - } + [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 { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *ret; size_t count = [array count]; id *tmp = [self allocMemoryForNItems: count withSize: sizeof(id)]; @try { - id *cArray = [array cArray]; - size_t i, j = 0; - - for (i = 0; i < count; i++) { - if (block(cArray[i], i)) - tmp[j++] = cArray[i]; - - [pool releaseObjects]; - } - - [pool release]; + __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: j]; + length: i]; } @finally { [self freeMemory: tmp]; } return ret; } - (id)reduceUsingBlock: (of_array_reduce_block_t)block { - OFAutoreleasePool *pool; - id *cArray; - size_t i, count = [array count]; - id current; + size_t count = [array count]; + __block id current; if (count == 0) return nil; if (count == 1) return [[[self firstObject] retain] autorelease]; - cArray = [array cArray]; - - pool = [[OFAutoreleasePool alloc] init]; - current = cArray[0]; + [self enumerateObjectsUsingBlock: ^ (id object, size_t index, + BOOL *stop) { + id new; - for (i = 1; i < count; i++) { - id old = current; + if (index == 0) { + current = [object retain]; + return; + } + @try { - current = [block(current, cArray[i]) retain]; - [pool releaseObjects]; + new = [block(current, object) retain]; } @finally { - [old release]; - } - } - - @try { - [pool release]; - } @catch (id e) { - [current release]; - @throw e; - } + [current release]; + } + current = new; + }]; return [current autorelease]; } #endif