Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -92,17 +92,10 @@ * * \param index The index of the object to remove */ - (void)removeObjectAtIndex: (size_t)index; -/** - * \brief Removes the specified amount of objects from the end of the OFArray. - * - * \param nObjects The number of objects to remove - */ -- (void)removeNObjects: (size_t)nObjects; - /** * \brief Removes the object in the specified range. * * \param range The range of the objects to remove */ Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -263,17 +263,10 @@ return; } } } -- (void)removeNObjects: (size_t)nObjects -{ - size_t count = [self count]; - - [self removeObjectsInRange: of_range(count - nObjects, nObjects)]; -} - - (void)removeObjectsInRange: (of_range_t)range { size_t i; for (i = 0; i < range.length; i++) @@ -280,16 +273,19 @@ [self removeObjectAtIndex: range.start]; } - (void)removeLastObject { - [self removeNObjects: 1]; + size_t count = [self count]; + + if (count > 0) + [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { - [self removeNObjects: [self count]]; + [self removeObjectsInRange: of_range(0, [self count])]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -25,12 +25,10 @@ #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" -#import "macros.h" - @implementation OFMutableArray_adjacent + (void)initialize { if (self == [OFMutableArray_adjacent class]) [self inheritMethodsFromClass: [OFArray_adjacent class]]; @@ -145,34 +143,10 @@ [object release]; mutations++; } -- (void)removeNObjects: (size_t)nObjects -{ - id *objects = [array cArray], *copy; - size_t i, count = [array count]; - - if (nObjects > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - copy = [self allocMemoryForNItems: nObjects - ofSize: sizeof(id)]; - memcpy(copy, objects + (count - nObjects), nObjects * sizeof(id)); - - @try { - [array removeItemsInRange: - of_range(count - nObjects, nObjects)]; - mutations++; - - for (i = 0; i < nObjects; i++) - [copy[i] release]; - } @finally { - [self freeMemory: copy]; - } -} - - (void)removeAllObjects { id *objects = [array cArray]; size_t i, count = [array count]; Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -121,15 +121,10 @@ R([m[0] removeObject: c_ary[0]]) && [m[0] count] == 2) TEST(@"-[removeObjectIdenticalTo:]", R([m[0] removeObjectIdenticalTo: c_ary[2]]) && [m[0] count] == 1) - [m[0] addObject: c_ary[0]]; - [m[0] addObject: c_ary[1]]; - TEST(@"-[removeNObjects:]", R([m[0] removeNObjects: 2]) && - [m[0] count] == 1 && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]]) - m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", R([m[1] removeObjectAtIndex: 1]) && [m[1] count] == 2 && [[m[1] objectAtIndex: 1] isEqual: c_ary[2]]) m[1] = [[a[0] mutableCopy] autorelease]; @@ -159,12 +154,13 @@ @"0", @"Bar", @"Baz", @"Foo", @"z", nil])]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) - EXPECT_EXCEPTION(@"Detect out of range in -[removeNObjects:]", - OFOutOfRangeException, [m[0] removeNObjects: [m[0] count] + 1]) + EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", + OFOutOfRangeException, [m[0] removeObjectsInRange: + of_range(0, [m[0] count] + 1)]) TEST(@"-[componentsJoinedByString:]", (a[1] = [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]) && [[a[1] componentsJoinedByString: @" "] isEqual: @"foo bar baz"] && (a[1] = [OFArray arrayWithObject: @"foo"]) && @@ -232,11 +228,11 @@ ok = YES; } TEST(@"Detection of mutation during Fast Enumeration", ok) - [m[0] removeNObjects: 1]; + [m[0] removeLastObject]; #endif #ifdef OF_HAVE_BLOCKS { __block BOOL ok = YES;