Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -26,11 +26,11 @@ + array; /** * \return The number of objects in the OFArray */ -- (size_t)objects; +- (size_t)count; /** * Clones the OFArray, creating a new one. * * \return A new autoreleased copy of the OFArray Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -37,23 +37,23 @@ } return self; } -- (size_t)objects +- (size_t)count { - return [array items]; + return [array count]; } - (id)copy { OFArray *new = [OFArray array]; OFObject **objs; size_t len, i; objs = [array data]; - len = [array items]; + len = [array count]; [new->array addNItems: len fromCArray: objs]; for (i = 0; i < len; i++) @@ -84,11 +84,11 @@ { OFObject **objs; size_t len, i; objs = [array data]; - len = [array items]; + len = [array count]; if (nobjects > len) @throw [OFOutOfRangeException newWithClass: isa]; for (i = len - nobjects; i < len; i++) @@ -104,11 +104,11 @@ OFObject **objs; size_t len, i; if (array != nil) { objs = [array data]; - len = [array items]; + len = [array count]; for (i = 0; i < len; i++) [objs[i] release]; [array release]; Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -20,11 +20,11 @@ */ @interface OFDataArray: OFObject { char *data; size_t itemsize; - size_t items; + size_t count; } /** * Creates a new OFDataArray whose items all have the same size. * @@ -52,11 +52,11 @@ - initWithItemSize: (size_t)is; /** * \return The number of items in the OFDataArray */ -- (size_t)items; +- (size_t)count; /** * \return The size of each item in the OFDataArray in bytes */ - (size_t)itemsize; Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -46,18 +46,18 @@ @throw [OFInvalidArgumentException newWithClass: c]; } data = NULL; itemsize = is; - items = 0; + count = 0; return self; } -- (size_t)items +- (size_t)count { - return items; + return count; } - (size_t)itemsize { return itemsize; @@ -68,81 +68,81 @@ return data; } - (void*)item: (size_t)index { - if (index >= items) + if (index >= count) @throw [OFOutOfRangeException newWithClass: isa]; return data + index * itemsize; } - (void*)last { - return data + (items - 1) * itemsize; + return data + (count - 1) * itemsize; } - add: (void*)item { - if (SIZE_MAX - items < 1) + if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMem: data - toNItems: items + 1 + toNItems: count + 1 withSize: itemsize]; - memcpy(data + items++ * itemsize, item, itemsize); + memcpy(data + count++ * itemsize, item, itemsize); return self; } - addNItems: (size_t)nitems fromCArray: (void*)carray { - if (nitems > SIZE_MAX - items) + if (nitems > SIZE_MAX - count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMem: data - toNItems: items + nitems + toNItems: count + nitems withSize: itemsize]; - memcpy(data + items * itemsize, carray, nitems * itemsize); - items += nitems; + memcpy(data + count * itemsize, carray, nitems * itemsize); + count += nitems; return self; } - removeNItems: (size_t)nitems { - if (nitems > items) + if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; data = [self resizeMem: data - toNItems: items - nitems + toNItems: count - nitems withSize: itemsize]; - items -= nitems; + count -= nitems; return self; } - (id)copy { OFDataArray *new = [OFDataArray dataArrayWithItemSize: itemsize]; - [new addNItems: items + [new addNItems: count fromCArray: data]; return new; } - (BOOL)isEqual: (id)obj { if (![obj isKindOf: [OFDataArray class]]) return NO; - if ([obj items] != items || [obj itemsize] != itemsize) + if ([obj count] != count || [obj itemsize] != itemsize) return NO; - if (memcmp([obj data], data, items * itemsize)) + if (memcmp([obj data], data, count * itemsize)) return NO; return YES; } @@ -155,33 +155,33 @@ andSelector: _cmd]; if ([obj itemsize] != itemsize) @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; - if ([obj items] == items) - return memcmp(data, [obj data], items * itemsize); + if ([obj count] == count) + return memcmp(data, [obj data], count * itemsize); + + if (count > [obj count]) { + if ((ret = memcmp(data, [obj data], [obj count] * itemsize))) + return ret; - if (items > [obj items]) { - if ((ret = memcmp(data, [obj data], [obj items] * itemsize))) + return *(char*)[self item: [obj count]]; + } else { + if ((ret = memcmp(data, [obj data], count * itemsize))) return ret; - return *(char*)[self item: [obj items]]; - } else { - if ((ret = memcmp(data, [obj data], items * itemsize))) - return ret; - - return *(char*)[obj item: [self items]] * -1; + return *(char*)[obj item: count] * -1; } } - (uint32_t)hash { uint32_t hash; size_t i; OF_HASH_INIT(hash); - for (i = 0; i < items * itemsize; i++) + for (i = 0; i < count * itemsize; i++) OF_HASH_ADD(hash, ((char*)data)[i]); OF_HASH_FINALIZE(hash); return hash; } @@ -201,20 +201,20 @@ - add: (void*)item { size_t nsize; - if (SIZE_MAX - items < 1 || items + 1 > SIZE_MAX / itemsize) + if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; - nsize = ((items + 1) * itemsize + lastpagebyte) & ~lastpagebyte; + nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data toSize: nsize]; - memcpy(data + items++ * itemsize, item, itemsize); + memcpy(data + count++ * itemsize, item, itemsize); size = nsize; return self; } @@ -221,50 +221,50 @@ - addNItems: (size_t)nitems fromCArray: (void*)carray { size_t nsize; - if (nitems > SIZE_MAX - items || items + nitems > SIZE_MAX / itemsize) + if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize) @throw [OFOutOfRangeException newWithClass: isa]; - nsize = ((items + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; + nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data toSize: nsize]; - memcpy(data + items * itemsize, carray, nitems * itemsize); - items += nitems; + memcpy(data + count * itemsize, carray, nitems * itemsize); + count += nitems; size = nsize; return self; } - removeNItems: (size_t)nitems { size_t nsize; - if (nitems > items) + if (nitems > count) @throw [OFOutOfRangeException newWithClass: isa]; - nsize = ((items - nitems) * itemsize + lastpagebyte) & ~lastpagebyte; + nsize = ((count - nitems) * itemsize + lastpagebyte) & ~lastpagebyte; if (size != nsize) data = [self resizeMem: data toSize: nsize]; - items -= nitems; + count -= nitems; size = nsize; return self; } - (id)copy { OFDataArray *new = [OFDataArray bigDataArrayWithItemSize: itemsize]; - [new addNItems: items + [new addNItems: count fromCArray: data]; return new; } @end Index: tests/OFDataArray/OFDataArray.m ================================================================== --- tests/OFDataArray/OFDataArray.m +++ tests/OFDataArray/OFDataArray.m @@ -68,33 +68,33 @@ puts("Adding multiple items at once..."); \ p = [a allocWithSize: 8192]; \ memset(p, 64, 8192); \ [a addNItems: 2 \ fromCArray: p]; \ - if (!memcmp([a last], [a item: [a items] - 2], 4096) && \ - !memcmp([a item: [a items] - 2], p, 4096)) \ - puts("[a last], [a item: [a items] - 2] and p match!"); \ + if (!memcmp([a last], [a item: [a count] - 2], 4096) && \ + !memcmp([a item: [a count] - 2], p, 4096)) \ + puts("[a last], [a item: [a count] - 2] and p match!"); \ else { \ - puts("[a last], [a item: [a items] - 2] and p did not match!");\ + puts("[a last], [a item: [a count] - 2] and p did not match!");\ abort(); \ } \ [a freeMem: p]; \ \ - i = [a items]; \ + i = [a count]; \ puts("Removing 2 items..."); \ [a removeNItems: 2]; \ - if ([a items] + 2 != i) { \ - puts("[a items] + 2 != i!"); \ + if ([a count] + 2 != i) { \ + puts("[a count] + 2 != i!"); \ abort(); \ } \ \ puts("Trying to remove more data than we added..."); \ - CATCH_EXCEPTION([a removeNItems: [a items] + 1], \ + CATCH_EXCEPTION([a removeNItems: [a count] + 1], \ OFOutOfRangeException); \ \ puts("Trying to access an index that does not exist..."); \ - CATCH_EXCEPTION([a item: [a items]], OFOutOfRangeException); \ + CATCH_EXCEPTION([a item: [a count]], OFOutOfRangeException); \ \ [a release]; \ \ puts("Creating new array and using it to build a string..."); \ a = [[type alloc] initWithItemSize: 1]; \