Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -270,10 +270,26 @@ * * \return A copy of the array with the order reversed */ - (OFArray*)reversedArray; +/** + * \brief Creates a new array with the specified object added. + * + * \param object The object to add + * \return A new array with the specified object added + */ +- (OFArray*)arrayByAddingObject: (id)object; + +/** + * \brief Creates a new array with the objects from the specified array added. + * + * \param array The array with objects to add + * \return A new array with the objects from the specified array added + */ +- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array; + #ifdef OF_HAVE_BLOCKS /** * \brief Executes a block for each object. * * \param block The block to execute for each object Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -601,10 +601,30 @@ if (stop) break; } } #endif + +- (OFArray*)arrayByAddingObject: (id)object +{ + OFMutableArray *ret = [[self mutableCopy] autorelease]; + + [ret addObject: object]; + [ret makeImmutable]; + + return ret; +} + +- (OFArray*)arrayByAddingObjectsFromArray: (OFArray*)array +{ + OFMutableArray *ret = [[self mutableCopy] autorelease]; + + [ret addObjectsFromArray: array]; + [ret makeImmutable]; + + return ret; +} #ifdef OF_HAVE_BLOCKS - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -30,19 +30,35 @@ * * \param object An object to add */ - (void)addObject: (id)object; +/** + * \brief Adds the objects from the specified OFArray to the end of the array. + * + * \brief array An array of objects to add + */ +- (void)addObjectsFromArray: (OFArray*)array; + /** * \brief Inserts an object to the OFArray at the specified index. * * \param object An object to add * \param index The index where the object should be inserted */ - (void)insertObject: (id)object atIndex: (size_t)index; +/** + * \brief Inserts the objects from the specified OFArray at the specified index. + * + * \param array An array of objects + * \param index The index where the objects should be inserted + */ +- (void)insertObjectsFromArray: (OFArray*)array + atIndex: (size_t)index; + /** * \brief Replaces the first object equivalent to the specified object with the * other specified object. * * \param oldObject The object to replace Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -180,17 +180,42 @@ - (void)addObject: (id)object { [self insertObject: object atIndex: [self count]]; } + +- (void)addObjectsFromArray: (OFArray*)array +{ + [self insertObjectsFromArray: array + atIndex: [self count]]; +} - (void)insertObject: (id)object atIndex: (size_t)index { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } + +- (void)insertObjectsFromArray: (OFArray*)array + atIndex: (size_t)index +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFEnumerator *enumerator = [array objectEnumerator]; + size_t i, count = [array count]; + + for (i = 0; i < count; i++) { + id object = [enumerator nextObject]; + + assert(object != nil); + + [self insertObject: object + atIndex: index + i]; + } + + [pool release]; +} - (void)replaceObjectAtIndex: (size_t)index withObject: (id)object { @throw [OFNotImplementedException exceptionWithClass: isa Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -47,10 +47,26 @@ { [array insertItem: &object atIndex: index]; [object retain]; + mutations++; +} + +- (void)insertObjectsFromArray: (OFArray*)array_ + atIndex: (size_t)index +{ + id *objects = [array_ objects]; + size_t i, count = [array_ count]; + + [array insertItemsFromCArray: objects + atIndex: index + count: count]; + + for (i = 0; i < count; i++) + [objects[i] retain]; + mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject