diff --git a/ChangeLog b/ChangeLog index 53c4c5334..36cdb3545 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2009-02-04 David Chisnall + + * Source/GSArray.m: Firther fast enumeration bugfixes. + * Source/GSEnumerator.m: ditto. + 2009-02-03 Richard Frith-Macdonald * Source/NSZone.m: restore binary compatibility with earlier code. + Thanks to David Chisnall for the idea. 2009-01-30 Richard Frith-Macdonald diff --git a/Source/GSArray.m b/Source/GSArray.m index a8d22eaae..9e1e9cf9d 100644 --- a/Source/GSArray.m +++ b/Source/GSArray.m @@ -373,8 +373,11 @@ static Class GSInlineArrayClass; count: (NSUInteger)len { /* For immutable arrays we can return the contents pointer directly. */ - state->itemsPtr = _contents_array; - return _count; + NSUInteger count = _count - state->state; + state->mutationsPtr = (unsigned long *)self; + state->itemsPtr = _contents_array + state->state; + state->state += count; + return count; } @end @@ -903,15 +906,15 @@ static Class GSInlineArrayClass; * iteration. If it changes during the iteration then * objc_enumerationMutation() will be called, throwing an exception. */ - state->mutationsPtr = (unsigned long*)_version; + state->mutationsPtr = (unsigned long *)&_version; count = MIN(len, _count - state->state); /* If a mutation has occurred then it's possible that we are being asked to * get objects from after the end of the array. Don't pass negative values * to memcpy. */ - if (count <= 0) + if (count >= 0) { - memcpy(stackbuf, _contents_array, count); + memcpy(stackbuf, _contents_array + state->state, count * sizeof(id)); state->state += count; } else diff --git a/Source/NSEnumerator.m b/Source/NSEnumerator.m index 297fcc754..2893d4141 100644 --- a/Source/NSEnumerator.m +++ b/Source/NSEnumerator.m @@ -81,6 +81,8 @@ IMP nextObject = [self methodForSelector: @selector(nextObject)]; int i; + state->itemsPtr = stackbuf; + state->mutationsPtr = (unsigned long*)self; for (i = 0; i < len; i++) { id next = nextObject(self, @selector(nextObject)); @@ -91,7 +93,6 @@ } *(stackbuf+i) = next; } - state->itemsPtr = stackbuf; return len; } @end