@@ -60,138 +60,141 @@ - (of_list_object_t*)lastListObject; { return lastListObject; } -- (of_list_object_t*)appendObject: (id)obj -{ - of_list_object_t *o; - - o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; - o->object = [obj retain]; - o->next = NULL; - o->prev = lastListObject; - - if (lastListObject != NULL) - lastListObject->next = o; - - lastListObject = o; - if (firstListObject == NULL) - firstListObject = o; - - count++; - mutations++; - - return o; -} - -- (of_list_object_t*)prependObject: (id)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++; - mutations++; - - return o; -} - -- (of_list_object_t*)insertObject: (id)obj - beforeListObject: (of_list_object_t*)listobj -{ - of_list_object_t *o; - - o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; - o->object = [obj retain]; - o->next = listobj; - o->prev = listobj->prev; - - if (listobj->prev != NULL) - listobj->prev->next = o; - - listobj->prev = o; - - if (listobj == firstListObject) - firstListObject = o; - - count++; - mutations++; - - return o; -} - -- (of_list_object_t*)insertObject: (id)obj - afterListObject: (of_list_object_t*)listobj -{ - of_list_object_t *o; - - o = [self allocMemoryWithSize: sizeof(of_list_object_t)]; - o->object = [obj retain]; - o->next = listobj->next; - o->prev = listobj; - - if (listobj->next != NULL) - listobj->next->prev = o; - - listobj->next = o; - - if (listobj == lastListObject) - lastListObject = o; - - count++; - mutations++; - - return o; -} - -- (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 (firstListObject == listobj) - firstListObject = listobj->next; - if (lastListObject == listobj) - lastListObject = listobj->prev; - - count--; - mutations++; - - [listobj->object release]; - - [self freeMemory: listobj]; +- (of_list_object_t*)appendObject: (id)object +{ + of_list_object_t *listObject; + + listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; + listObject->object = [object retain]; + listObject->next = NULL; + listObject->previous = lastListObject; + + if (lastListObject != NULL) + lastListObject->next = listObject; + + lastListObject = listObject; + if (firstListObject == NULL) + firstListObject = listObject; + + count++; + mutations++; + + return listObject; +} + +- (of_list_object_t*)prependObject: (id)object +{ + of_list_object_t *listObject; + + listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; + listObject->object = [object retain]; + listObject->next = firstListObject; + listObject->previous = NULL; + + if (firstListObject != NULL) + firstListObject->previous = listObject; + + firstListObject = listObject; + if (lastListObject == NULL) + lastListObject = listObject; + + count++; + mutations++; + + return listObject; +} + +- (of_list_object_t*)insertObject: (id)object + beforeListObject: (of_list_object_t*)listObject +{ + of_list_object_t *newListObject; + + newListObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; + newListObject->object = [object retain]; + newListObject->next = listObject; + newListObject->previous = listObject->previous; + + if (listObject->previous != NULL) + listObject->previous->next = newListObject; + + listObject->previous = newListObject; + + if (listObject == firstListObject) + firstListObject = newListObject; + + count++; + mutations++; + + return newListObject; +} + +- (of_list_object_t*)insertObject: (id)object + afterListObject: (of_list_object_t*)listObject +{ + of_list_object_t *newListObject; + + newListObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; + newListObject->object = [object retain]; + newListObject->next = listObject->next; + newListObject->previous = listObject; + + if (listObject->next != NULL) + listObject->next->previous = newListObject; + + listObject->next = newListObject; + + if (listObject == lastListObject) + lastListObject = newListObject; + + count++; + mutations++; + + return newListObject; +} + +- (void)removeListObject: (of_list_object_t*)listObject +{ + if (listObject->previous != NULL) + listObject->previous->next = listObject->next; + if (listObject->next != NULL) + listObject->next->previous = listObject->previous; + + if (firstListObject == listObject) + firstListObject = listObject->next; + if (lastListObject == listObject) + lastListObject = listObject->previous; + + count--; + mutations++; + + [listObject->object release]; + + [self freeMemory: listObject]; } - (size_t)count { return count; } -- (BOOL)isEqual: (id)obj +- (BOOL)isEqual: (id)object { + OFList *otherList; of_list_object_t *iter, *iter2; - if (![obj isKindOfClass: [OFList class]]) + if (![object isKindOfClass: [OFList class]]) return NO; - if ([(OFList*)obj count] != count) + otherList = (OFList*)object; + + if ([otherList count] != count) return NO; - for (iter = firstListObject, iter2 = [(OFList*)obj firstListObject]; + for (iter = firstListObject, iter2 = [otherList firstListObject]; iter != NULL && iter2 != NULL; iter = iter->next, iter2 = iter2->next) if (![iter->object isEqual: iter2->object]) return NO; @@ -199,70 +202,71 @@ assert(iter == NULL && iter2 == NULL); return YES; } -- (BOOL)containsObject: (id)obj +- (BOOL)containsObject: (id)object { of_list_object_t *iter; if (count == 0) return NO; for (iter = firstListObject; iter != NULL; iter = iter->next) - if ([iter->object isEqual: obj]) + if ([iter->object isEqual: object]) return YES; return NO; } -- (BOOL)containsObjectIdenticalTo: (id)obj +- (BOOL)containsObjectIdenticalTo: (id)object { of_list_object_t *iter; if (count == 0) return NO; for (iter = firstListObject; iter != NULL; iter = iter->next) - if (iter->object == obj) + if (iter->object == object) return YES; return NO; } - copy { - OFList *new = [[OFList alloc] init]; - of_list_object_t *iter, *o, *prev; + OFList *copy = [[OFList alloc] init]; + of_list_object_t *iter, *listObject, *previous; - o = NULL; - prev = NULL; + listObject = NULL; + previous = NULL; @try { 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->firstListObject == NULL) - new->firstListObject = o; - if (prev != NULL) - prev->next = o; - - new->count++; - - prev = o; + listObject = [copy allocMemoryWithSize: + sizeof(of_list_object_t)]; + listObject->object = [iter->object retain]; + listObject->next = NULL; + listObject->previous = previous; + + if (copy->firstListObject == NULL) + copy->firstListObject = listObject; + if (previous != NULL) + previous->next = listObject; + + copy->count++; + + previous = listObject; } } @catch (id e) { - [new release]; + [copy release]; @throw e; } - new->lastListObject = o; + copy->lastListObject = listObject; - return new; + return copy; } - (uint32_t)hash { of_list_object_t *iter;