Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -8,10 +8,12 @@ * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" + +#include #import "OFMutableArray.h" #import "OFExceptions.h" @implementation OFMutableArray @@ -105,12 +107,13 @@ OFObject **objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objs[i] isEqual: obj]) { - [objs[i] release]; + OFObject *obj = objs[i]; [array removeItemAtIndex: i]; + [obj release]; } } return self; } @@ -120,12 +123,12 @@ OFObject **objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objs[i] == obj) { - [obj release]; [array removeItemAtIndex: i]; + [obj release]; } } return self; } @@ -136,37 +139,53 @@ atIndex: index]; } - removeNObjects: (size_t)nobjects { - OFObject **objs = [array cArray]; + OFObject **objs = [array cArray], **copy; size_t i, count = [array count]; if (nobjects > count) @throw [OFOutOfRangeException newWithClass: isa]; - for (i = count - nobjects; i < count; i++) - [objs[i] release]; + copy = [self allocMemoryForNItems: nobjects + withSize: sizeof(OFObject*)]; + memcpy(copy, objs + (count - nobjects), nobjects * sizeof(OFObject*)); + + @try { + [array removeNItems: nobjects]; - [array removeNItems: nobjects]; + for (i = 0; i < nobjects; i++) + [copy[i] release]; + } @finally { + [self freeMemory: copy]; + } return self; } - removeNObjects: (size_t)nobjects atIndex: (size_t)index { - OFObject **objs = [array cArray]; + OFObject **objs = [array cArray], **copy; size_t i, count = [array count]; if (nobjects > count - index) @throw [OFOutOfRangeException newWithClass: isa]; - for (i = index; i < count && i < index + nobjects; i++) - [objs[i] release]; + copy = [self allocMemoryForNItems: nobjects + withSize: sizeof(OFObject*)]; + memcpy(copy, objs + index, nobjects * sizeof(OFObject*)); + + @try { + [array removeNItems: nobjects + atIndex: index]; - [array removeNItems: nobjects - atIndex: index]; + for (i = 0; i < nobjects; i++) + [copy[i] release]; + } @finally { + [self freeMemory: copy]; + } return self; } @end