Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -29,18 +29,18 @@ /** * \brief A class which provides easy to use double-linked lists. */ @interface OFList: OFObject { - of_list_object_t *first; - of_list_object_t *last; + of_list_object_t *firstListObject; + of_list_object_t *lastListObject; size_t count; } #ifdef OF_HAVE_PROPERTIES -@property (readonly) of_list_object_t *first; -@property (readonly) of_list_object_t *last; +@property (readonly) of_list_object_t *firstListObject; +@property (readonly) of_list_object_t *lastListObject; @property (readonly) size_t count; #endif /** * \return A new autoreleased OFList @@ -48,36 +48,36 @@ + list; /** * \return The first list object in the list */ -- (of_list_object_t*)first; +- (of_list_object_t*)firstListObject; /** * \return The last list object in the list */ -- (of_list_object_t*)last; +- (of_list_object_t*)lastListObject; /** * Appends an object to the list. * * \param obj The object to append * \return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)append: (OFObject*)obj; +- (of_list_object_t*)appendObject: (OFObject*)obj; /** * Prepends an object to the list. * * \param obj The object to prepend * \return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)prepend: (OFObject*)obj; +- (of_list_object_t*)prependObject: (OFObject*)obj; /** * Inserts an object before another object. * \param obj The object to insert * \param listobj The of_list_object_t of the object before which it should be @@ -84,12 +84,12 @@ * inserted * \return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)insert: (OFObject*)obj - before: (of_list_object_t*)listobj; +- (of_list_object_t*)insertObject: (OFObject*)obj + beforeListObject: (of_list_object_t*)listobj; /** * Inserts an object after another object. * \param obj The object to insert * \param listobj The of_list_object_t of the object after which it should be @@ -96,20 +96,20 @@ * inserted * \return An of_list_object_t, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its of_list_object_t. */ -- (of_list_object_t*)insert: (OFObject*)obj - after: (of_list_object_t*)listobj; +- (of_list_object_t*)insertObject: (OFObject*)obj + afterListObject: (of_list_object_t*)listobj; /** * Removes the object with the specified list object from the list. * * \param listobj The list object returned by append / prepend */ -- (void)remove: (of_list_object_t*)listobj; +- (void)removeListObject: (of_list_object_t*)listobj; /** * \return The number of items in the list. */ - (size_t)count; @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -25,84 +25,84 @@ - init { self = [super init]; - first = NULL; - last = NULL; + firstListObject = NULL; + lastListObject = NULL; return self; } - (void)dealloc { of_list_object_t *iter; - for (iter = first; iter != NULL; iter = iter->next) + for (iter = firstListObject; iter != NULL; iter = iter->next) [iter->object release]; [super dealloc]; } -- (of_list_object_t*)first +- (of_list_object_t*)firstListObject; { - return first; + return firstListObject; } -- (of_list_object_t*)last +- (of_list_object_t*)lastListObject; { - return last; + return lastListObject; } -- (of_list_object_t*)append: (OFObject*)obj +- (of_list_object_t*)appendObject: (OFObject*)obj { of_list_object_t *o; o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; o->object = [obj retain]; o->next = NULL; - o->prev = last; - - if (last != NULL) - last->next = o; - - last = o; - if (first == NULL) - first = o; + o->prev = lastListObject; + + if (lastListObject != NULL) + lastListObject->next = o; + + lastListObject = o; + if (firstListObject == NULL) + firstListObject = o; + + count++; + + [obj retain]; + + return o; +} + +- (of_list_object_t*)prependObject: (OFObject*)obj +{ + of_list_object_t *o; + + o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; + o->object = [obj retain]; + o->next = firstListObject; + o->prev = NULL; + + if (firstListObject != NULL) + firstListObject->prev = o; + + firstListObject = o; + if (lastListObject == NULL) + lastListObject = o; count++; [obj retain]; return o; } -- (of_list_object_t*)prepend: (OFObject*)obj -{ - of_list_object_t *o; - - o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; - o->object = [obj retain]; - o->next = first; - o->prev = NULL; - - if (first != NULL) - first->prev = o; - - first = o; - if (last == NULL) - last = o; - - count++; - - [obj retain]; - - return o; -} - -- (of_list_object_t*)insert: (OFObject*)obj - before: (of_list_object_t*)listobj +- (of_list_object_t*)insertObject: (OFObject*)obj + beforeListObject: (of_list_object_t*)listobj { of_list_object_t *o; o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; o->object = [obj retain]; @@ -112,22 +112,22 @@ if (listobj->prev != NULL) listobj->prev->next = o; listobj->prev = o; - if (listobj == first) - first = o; + if (listobj == firstListObject) + firstListObject = o; count++; [obj retain]; return o; } -- (of_list_object_t*)insert: (OFObject*)obj - after: (of_list_object_t*)listobj +- (of_list_object_t*)insertObject: (OFObject*)obj + afterListObject: (of_list_object_t*)listobj { of_list_object_t *o; o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; o->object = [obj retain]; @@ -137,31 +137,31 @@ if (listobj->next != NULL) listobj->next->prev = o; listobj->next = o; - if (listobj == last) - last = o; + if (listobj == lastListObject) + lastListObject = o; count++; [obj retain]; return o; } -- (void)remove: (of_list_object_t*)listobj +- (void)removeListObject: (of_list_object_t*)listobj { if (listobj->prev != NULL) listobj->prev->next = listobj->next; if (listobj->next != NULL) listobj->next->prev = listobj->prev; - if (first == listobj) - first = listobj->next; - if (last == listobj) - last = listobj->prev; + if (firstListObject == listobj) + firstListObject = listobj->next; + if (lastListObject == listobj) + lastListObject = listobj->prev; count--; [listobj->object release]; @@ -181,12 +181,13 @@ return NO; if ([(OFList*)obj count] != count) return NO; - for (iter = first, iter2 = [(OFList*)obj first]; iter != NULL && - iter2 != NULL; iter = iter->next, iter2 = iter2->next) + for (iter = firstListObject, iter2 = [(OFList*)obj firstListObject]; + iter != NULL && iter2 != NULL; + iter = iter->next, iter2 = iter2->next) if (![iter->object isEqual: iter2->object]) return NO; /* One is bigger than the other although we checked the count */ assert(iter == NULL && iter2 == NULL); @@ -201,18 +202,18 @@ o = NULL; prev = NULL; @try { - for (iter = first; iter != NULL; iter = iter->next) { + for (iter = firstListObject; iter != NULL; iter = iter->next) { o = [new allocMemoryWithSize: sizeof(of_list_object_t)]; o->object = [iter->object retain]; o->next = NULL; o->prev = prev; - if (new->first == NULL) - new->first = o; + if (new->firstListObject == NULL) + new->firstListObject = o; if (prev != NULL) prev->next = o; new->count++; @@ -223,11 +224,11 @@ } @catch (OFException *e) { [new release]; @throw e; } - new->last = o; + new->lastListObject = o; return new; } - (uint32_t)hash @@ -235,11 +236,11 @@ of_list_object_t *iter; uint32_t hash; OF_HASH_INIT(hash); - for (iter = first; iter != NULL; iter = iter->next) { + for (iter = firstListObject; iter != NULL; iter = iter->next) { uint32_t h = [iter->object hash]; OF_HASH_ADD(hash, h >> 24); OF_HASH_ADD(hash, (h >> 16) & 0xFF); OF_HASH_ADD(hash, (h >> 8) & 0xFF); Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -217,11 +217,12 @@ + (void)callAllDestructors { of_list_object_t *iter; @synchronized (tlskeys) { - for (iter = [tlskeys first]; iter != NULL; iter = iter->next) + for (iter = [tlskeys firstListObject]; iter != NULL; + iter = iter->next) ((OFTLSKey*)iter->object)->destructor(iter->object); } } - init @@ -236,11 +237,11 @@ destructor = NULL; @synchronized (tlskeys) { @try { - listobj = [tlskeys append: self]; + listobj = [tlskeys appendObject: self]; } @catch (OFException *e) { /* * We can't use [super dealloc] on OS X here. * Compiler bug? Anyway, [self dealloc] will do here * as we check listobj != NULL in dealloc. @@ -271,11 +272,11 @@ of_tlskey_free(key); @synchronized (tlskeys) { /* In case we called [self dealloc] in init */ if (listobj != NULL) - [tlskeys remove: listobj]; + [tlskeys removeListObject: listobj]; } [super dealloc]; } @end Index: tests/OFListTests.m ================================================================== --- tests/OFListTests.m +++ tests/OFListTests.m @@ -31,43 +31,50 @@ OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFList *list; TEST(@"+[list]", (list = [OFList list])) - TEST(@"-[append:]", [list append: strings[0]] && - [list append: strings[1]] && [list append: strings[2]]) - - TEST(@"-[first]", [[list first]->object isEqual: strings[0]]) - - TEST(@"-[first]->next", - [[list first]->next->object isEqual: strings[1]]) - - TEST(@"-[last]", [[list last]->object isEqual: strings[2]]) - - TEST(@"-[last]->prev", [[list last]->prev->object isEqual: strings[1]]) - - TEST(@"-[remove:]", R([list remove: [list last]]) && - [[list last]->object isEqual: strings[1]] && - R([list remove: [list first]]) && - [[list first]->object isEqual: [list last]->object]) - - TEST(@"-[insert:before:]", [list insert: strings[0] - before: [list last]] && - [[list last]->prev->object isEqual: strings[0]]) - - - TEST(@"-[insert:after:]", [list insert: strings[2] - after: [list first]->next] && - [[list last]->object isEqual: strings[2]]) + TEST(@"-[appendObject:]", [list appendObject: strings[0]] && + [list appendObject: strings[1]] && [list appendObject: strings[2]]) + + TEST(@"-[firstListObject]", + [[list firstListObject]->object isEqual: strings[0]]) + + TEST(@"-[firstListObject]->next", + [[list firstListObject]->next->object isEqual: strings[1]]) + + TEST(@"-[lastListObject]", + [[list lastListObject]->object isEqual: strings[2]]) + + TEST(@"-[lastListObject]->prev", + [[list lastListObject]->prev->object isEqual: strings[1]]) + + TEST(@"-[removeListObject:]", + R([list removeListObject: [list lastListObject]]) && + [[list lastListObject]->object isEqual: strings[1]] && + R([list removeListObject: [list firstListObject]]) && + [[list firstListObject]->object isEqual: + [list lastListObject]->object]) + + TEST(@"-[insertObject:beforeListObject:]", + [list insertObject: strings[0] + beforeListObject: [list lastListObject]] && + [[list lastListObject]->prev->object isEqual: strings[0]]) + + + TEST(@"-[insertObject:afterListObject:]", + [list insertObject: strings[2] + afterListObject: [list firstListObject]->next] && + [[list lastListObject]->object isEqual: strings[2]]) TEST(@"-[count]", [list count] == 3) TEST(@"-[copy]", (list = [[list copy] autorelease]) && - [[list first]->object isEqual: strings[0]] && - [[list first]->next->object isEqual: strings[1]] && - [[list last]->object isEqual: strings[2]]) + [[list firstListObject]->object isEqual: strings[0]] && + [[list firstListObject]->next->object isEqual: strings[1]] && + [[list lastListObject]->object isEqual: strings[2]]) TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]]) [pool drain]; } @end