Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -12,10 +12,11 @@ OFExceptions.m \ OFFile.m \ OFHashes.m \ OFIterator.m \ OFList.m \ + OFMutableArray.m \ OFMutableString.m \ OFNumber.m \ OFObject.m \ ${OFPLUGIN_M} \ OFSocket.m \ Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -60,5 +60,7 @@ * * \param nobjects The number of objects to remove */ - removeNObjects: (size_t)nobjects; @end + +#import "OFMutableArray.h" Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -15,11 +15,11 @@ #import "OFExceptions.h" @implementation OFArray + array { - return [[[OFArray alloc] init] autorelease]; + return [[[self alloc] init] autorelease]; } - init { self = [super init]; @@ -77,33 +77,18 @@ return *((OFObject**)[array last]); } - add: (OFObject*)obj { - [array add: &obj]; - [obj retain]; - - return self; + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; } - removeNObjects: (size_t)nobjects { - OFObject **objs; - size_t len, i; - - objs = [array data]; - len = [array count]; - - if (nobjects > len) - @throw [OFOutOfRangeException newWithClass: isa]; - - for (i = len - nobjects; i < len; i++) - [objs[i] release]; - - [array removeNItems: nobjects]; - - return self; + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; } - (void)dealloc { OFObject **objs; Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -93,11 +93,11 @@ } - addToPool: (OFObject*)obj { if (objects == nil) - objects = [[OFArray alloc] init]; + objects = [[OFMutableArray alloc] init]; [objects add: obj]; [obj release]; return self; Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -31,19 +31,10 @@ * \param is The size of each element in the OFDataArray * \return A new autoreleased OFDataArray */ + dataArrayWithItemSize: (size_t)is; -/* - * Creates a new OFDataArray optimized for big arrays whose items all have the - * same size, which means memory is allocated in pages rather than in bytes. - * - * \param is The size of each element in the OFBigDataArray - * \return A new autoreleased OFBigDataArray - */ -+ bigDataArrayWithItemSize: (size_t)is; - /** * Initializes an already allocated OFDataArray whose items all have the same * size. * * \param is The size of each element in the OFDataArray Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -24,16 +24,11 @@ extern int getpagesize(void); @implementation OFDataArray + dataArrayWithItemSize: (size_t)is { - return [[[OFDataArray alloc] initWithItemSize: is] autorelease]; -} - -+ bigDataArrayWithItemSize: (size_t)is -{ - return [[[OFBigDataArray alloc] initWithItemSize: is] autorelease]; + return [[[self alloc] initWithItemSize: is] autorelease]; } - initWithItemSize: (size_t)is { Class c; @@ -257,13 +252,13 @@ return self; } - (id)copy { - OFDataArray *new = [OFDataArray bigDataArrayWithItemSize: itemsize]; + OFDataArray *new = [OFBigDataArray dataArrayWithItemSize: itemsize]; [new addNItems: count fromCArray: data]; return new; } @end ADDED src/OFMutableArray.h Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2008 - 2009 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#import "OFArray.h" + +/** + * The OFMutableArray class provides a class for storing, adding and removing + * objects in an array. + */ +@interface OFMutableArray: OFArray +@end ADDED src/OFMutableArray.m Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008 - 2009 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#import "config.h" + +#import "OFMutableArray.h" +#import "OFExceptions.h" + +@implementation OFMutableArray +- add: (OFObject*)obj +{ + [array add: &obj]; + [obj retain]; + + return self; +} + +- removeNObjects: (size_t)nobjects +{ + OFObject **objs; + size_t len, i; + + objs = [array data]; + len = [array count]; + + if (nobjects > len) + @throw [OFOutOfRangeException newWithClass: isa]; + + for (i = len - nobjects; i < len; i++) + [objs[i] release]; + + [array removeNItems: nobjects]; + + return self; +} +@end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -169,11 +169,11 @@ OFArray *array = nil; const char *delim = [delimiter cString]; size_t delim_len = [delimiter length]; size_t i, last; - array = [OFArray array]; + array = [OFMutableArray array]; for (i = 0, last = 0; i <= length; i++) { if (OF_UNLIKELY(i == length || !memcmp(string + i, delim, delim_len))) { OFString *str; Index: tests/OFDataArray/OFDataArray.m ================================================================== --- tests/OFDataArray/OFDataArray.m +++ tests/OFDataArray/OFDataArray.m @@ -127,11 +127,11 @@ puts("== TESTING OFBigArray =="); TEST(OFBigDataArray) pool = [[OFAutoreleasePool alloc] init]; x = [OFDataArray dataArrayWithItemSize: 1]; - y = [OFDataArray bigDataArrayWithItemSize: 1]; + y = [OFBigDataArray dataArrayWithItemSize: 1]; if (![x isEqual: y]) { puts("FAIL 1!"); return 1; } @@ -147,11 +147,11 @@ return 1; } [pool releaseObjects]; x = [OFDataArray dataArrayWithItemSize: 2]; - y = [OFDataArray bigDataArrayWithItemSize: 4]; + y = [OFBigDataArray dataArrayWithItemSize: 4]; if ([x isEqual: y]) { puts("FAIL 4!"); return 1; }