Index: src/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -92,18 +92,21 @@ - initWithArray: (OFArray*)array { id *objects; size_t i, count; - self = [self init]; + self = [super init]; if (array == nil) return self; @try { objects = [array objects]; count = [array count]; + + _array = [[OFDataArray alloc] initWithItemSize: sizeof(id) + capacity: count]; } @catch (id e) { [self release]; @throw e; } Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -17,11 +17,10 @@ #include "config.h" #include #import "OFAutoreleasePool.h" -#import "OFArray.h" #import "macros.h" #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) # import "threading.h" Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -116,11 +116,11 @@ * @brief Initializes an already allocated OFDictionary with the specified key * and object. * * @param key The key * @param object The object - * @return A new initialized OFDictionary + * @return An initialized OFDictionary */ - initWithObject: (id)object forKey: (id)key; /*! @@ -127,11 +127,11 @@ * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param keys An array of keys * @param objects An array of objects - * @return A new initialized OFDictionary + * @return An initialized OFDictionary */ - initWithObjects: (OFArray*)objects forKeys: (OFArray*)keys; /*! @@ -139,11 +139,11 @@ * and objects. * * @param keys An array of keys * @param objects An array of objects * @param count The number of objects in the arrays - * @return A new initialized OFDictionary + * @return An initialized OFDictionary */ - initWithObjects: (id const*)objects forKeys: (id const*)keys count: (size_t)count; @@ -150,21 +150,21 @@ /*! * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param firstKey The first key - * @return A new initialized OFDictionary + * @return An initialized OFDictionary */ - initWithKeysAndObjects: (id)firstKey, ... OF_SENTINEL; /*! * @brief Initializes an already allocated OFDictionary with the specified key * and va_list. * * @param firstKey The first key * @param arguments A va_list of the other arguments - * @return A new initialized OFDictionary + * @return An initialized OFDictionary */ - initWithKey: (id)firstKey arguments: (va_list)arguments; /*! Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -23,10 +23,28 @@ /*! * @brief An abstract class for storing, adding and removing objects in an * array. */ @interface OFMutableArray: OFArray +/*! + * @brief Creates a new OFMutableArray with enough memory to hold the specified + * number of objects. + * + * @param capacity The initial capacity for the OFMutableArray + * @return A new autoreleased OFMutableArray + */ ++ (instancetype)arrayWithCapacity: (size_t)capacity; + +/*! + * @brief Initializes an already allocated OFMutableArray with enough memory to + * hold the specified number of objects. + * + * @param capacity The initial capacity for the OFMutableArray + * @return An initialized OFMutableArray + */ +- initWithCapacity: (size_t)capacity; + /*! * @brief Adds an object to the end of the array. * * @param object An object to add */ Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -84,10 +84,15 @@ @implementation OFMutableArray_placeholder - init { return (id)[[OFMutableArray_adjacent alloc] init]; } + +- initWithCapacity: (size_t)capacity +{ + return (id)[[OFMutableArray_adjacent alloc] initWithCapacity: capacity]; +} - initWithObject: (id)object { return (id)[[OFMutableArray_adjacent alloc] initWithObject: object]; } @@ -166,10 +171,15 @@ if (self == [OFMutableArray class]) return (id)&placeholder; return [super alloc]; } + ++ (instancetype)arrayWithCapacity: (size_t)capacity +{ + return [[[self alloc] initWithCapacity: capacity] autorelease]; +} - init { if (object_getClass(self) == [OFMutableArray class]) { @try { @@ -181,10 +191,22 @@ } } return [super init]; } + +- initWithCapacity: (size_t)capacity +{ + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } + + abort(); +} - copy { return [[OFArray alloc] initWithArray: self]; } Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -30,10 +30,25 @@ + (void)initialize { if (self == [OFMutableArray_adjacent class]) [self inheritMethodsFromClass: [OFArray_adjacent class]]; } + +- initWithCapacity: (size_t)capacity +{ + self = [super init]; + + @try { + _array = [[OFDataArray alloc] initWithItemSize: sizeof(id) + capacity: capacity]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (void)addObject: (id)object { if (object == nil) @throw [OFInvalidArgumentException Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -36,11 +36,11 @@ /*! * @brief Initializes an already allocated OFMutableDictionary with enough * memory to hold the specified number of objects. * * @param capacity The initial capacity for the OFMutableDictionary - * @return A new initialized OFMutableDictionary + * @return An initialized OFMutableDictionary */ - initWithCapacity: (size_t)capacity; /*! * @brief Sets an object for a key. Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -135,11 +135,11 @@ return (id)&placeholder; return [super alloc]; } -+ dictionaryWithCapacity: (size_t)capacity ++ (instancetype)dictionaryWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } - init