Index: src/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -328,10 +328,35 @@ OF_HASH_FINALIZE(hash); return hash; } + +- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state + objects: (id*)objects + count: (int)count_ +{ + size_t count = [_array count]; + + if (count > INT_MAX) + /* + * Use the implementation from OFArray, which is slower, but can + * enumerate in chunks. + */ + return [super countByEnumeratingWithState: state + objects: objects + count: count_]; + + if (state->state >= count) + return 0; + + state->state = count; + state->itemsPtr = [_array items]; + state->mutationsPtr = (unsigned long*)self; + + return (int)count; +} #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { id *objects = [_array items]; Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -298,24 +298,35 @@ } } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects - count: (int)count -{ - /* - * Super means the implementation from OFArray here, as OFMutableArray - * does not reimplement it. As OFArray_adjacent does not reimplement it - * either, this is fine. - */ - int ret = [super countByEnumeratingWithState: state - objects: objects - count: count]; - + count: (int)count_ +{ + size_t count = [_array count]; + + if (count > INT_MAX) { + /* + * Use the implementation from OFArray (OFMutableArray does not + * have one), which is slower, but can enumerate in chunks, and + * set the mutations pointer. + */ + int ret = [super countByEnumeratingWithState: state + objects: objects + count: count_]; + state->mutationsPtr = &_mutations; + return ret; + } + + if (state->state >= count) + return 0; + + state->state = count; + state->itemsPtr = [_array items]; state->mutationsPtr = &_mutations; - return ret; + return (int)count; } - (OFEnumerator*)objectEnumerator { return [[[OFArrayEnumerator alloc]