Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -180,13 +180,12 @@ * * @param objects A C array of objects * @param count The length of the C array * @return A new autoreleased OFArray */ -+ (instancetype) - arrayWithObjects: (ObjectType const _Nonnull *_Nonnull)objects - count: (size_t)count; ++ (instancetype)arrayWithObjects: (ObjectType const _Nonnull *_Nonnull)objects + count: (size_t)count; /** * @brief Initializes an OFArray with the specified object. * * @param object An object @@ -436,14 +435,15 @@ */ - (OFArray OF_GENERIC(ObjectType) *)arrayByAddingObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array; /** - * @brief Creates a new array with the specified object removed. + * @brief Creates a new array with all occurrences of the specified object + * removed. * * @param object The object to remove - * @return A new array with the specified object removed + * @return A new array with all occurrences of the specified object removed */ - (OFArray OF_GENERIC(ObjectType) *)arrayByRemovingObject: (ObjectType)object; #ifdef OF_HAVE_BLOCKS /** Index: src/OFMutableAdjacentArray.m ================================================================== --- src/OFMutableAdjacentArray.m +++ src/OFMutableAdjacentArray.m @@ -105,12 +105,10 @@ for (size_t i = 0; i < count; i++) { if ([objects[i] isEqual: oldObject]) { [newObject retain]; [objects[i] release]; objects[i] = newObject; - - return; } } } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object @@ -171,11 +169,14 @@ [_array removeItemAtIndex: i]; _mutations++; [object release]; - return; + objects = _array.items; + i--; + count--; + continue; } } } - (void)removeObjectIdenticalTo: (id)object @@ -194,11 +195,14 @@ [_array removeItemAtIndex: i]; _mutations++; [object release]; - return; + objects = _array.items; + i--; + count--; + continue; } } } - (void)removeObjectAtIndex: (size_t)idx Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -92,11 +92,11 @@ */ - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array atIndex: (size_t)index; /** - * @brief Replaces the first object equivalent to the specified object with the + * @brief Replaces all objects equivalent to the specified object with the * other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ @@ -131,18 +131,18 @@ */ - (void)replaceObjectIdenticalTo: (ObjectType)oldObject withObject: (ObjectType)newObject; /** - * @brief Removes the first object equivalent to the specified object. + * @brief Removes all objects equivalent to the specified object. * * @param object The object to remove */ - (void)removeObject: (ObjectType)object; /** - * @brief Removes the first object that has the same address as the specified + * @brief Removes all objects that have the same address as the specified * object. * * @param object The object to remove */ - (void)removeObjectIdenticalTo: (ObjectType)object; @@ -153,11 +153,11 @@ * @param index The index of the object to remove */ - (void)removeObjectAtIndex: (size_t)index; /** - * @brief Removes the object in the specified range. + * @brief Removes the objects in the specified range. * * @param range The range of the objects to remove */ - (void)removeObjectsInRange: (OFRange)range; Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -293,16 +293,13 @@ if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = self.count; - for (size_t i = 0; i < count; i++) { - if ([[self objectAtIndex: i] isEqual: oldObject]) { + for (size_t i = 0; i < count; i++) + if ([[self objectAtIndex: i] isEqual: oldObject]) [self replaceObjectAtIndex: i withObject: newObject]; - return; - } - } } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { size_t count; @@ -337,11 +334,13 @@ for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: object]) { [self removeObjectAtIndex: i]; - return; + i--; + count--; + continue; } } } - (void)removeObjectIdenticalTo: (id)object @@ -355,11 +354,13 @@ for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == object) { [self removeObjectAtIndex: i]; - return; + i--; + count--; + continue; } } } - (void)removeObjectsInRange: (OFRange)range Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -208,11 +208,13 @@ [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]]) TEST(@"-[removeObject:]", R([mutableArray1 removeObject: cArray[0]]) && - mutableArray1.count == 2) + mutableArray1.count == 1) + + [mutableArray1 addObject: cArray[0]]; TEST(@"-[removeObjectIdenticalTo:]", R([mutableArray1 removeObjectIdenticalTo: cArray[2]]) && mutableArray1.count == 1)