X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fadt%2Fplist.c;h=fba92a816a2f74593d359607b55127c52bed13ec;hb=aec2ca30abe2ff7d0053c29dfc8ee517672bb3c1;hp=b18b34235ec4a312673460b6472717af64074f70;hpb=cedd573630a6ad0eca287cc3cb5ed10e4c1423be;p=libfirm diff --git a/ir/adt/plist.c b/ir/adt/plist.c index b18b34235..fba92a816 100644 --- a/ir/adt/plist.c +++ b/ir/adt/plist.c @@ -5,58 +5,20 @@ * This list uses an obstack and a free-list to efficiently manage its * elements. * @author Kimon Hoffmann - * @date 17.07.2005 + * @date 14.07.2005 * @note Until now the code is entirely untested so it probably contains * plenty of errors. */ #include -#include "obst.h" #include "plist.h" -/** - * Structure for one entry of the double linked pointer list. - */ -struct PListElement { - PListElement* next; - PListElement* prev; - void* data; -}; - -/** - * The list data type. - */ -struct PList { - /** - * The obastack used for all allocations. - */ - struct obstack obst; - /** - * First element in the list. - */ - PListElement* firstElement; - /** - * Last element in the list. - */ - PListElement* lastElement; - /** - * Current numner of elements in the list. - */ - int elementCount; - /** - * First element in the free list. - * Please note that the free list is a single linked list and all back - * references are invalid. - */ - PListElement* firstFreeElement; -}; - /** * Helper macro that returns a new uninitialized list element by either * fetching one from the free-list or allocating a new one on the lists * obstack. * @param list the list for which to allocate the element. - * @return the newlyallocated, uninitialized element. + * @return the newly allocated, uninitialized element. */ static PListElement* allocate_element(PList* list) { PListElement* newElement; @@ -116,10 +78,12 @@ void plist_insert_front(PList* list, void* value) { } void plist_insert_before(PList* list, PListElement* element, void* value) { + PListElement* prevElement; PListElement* newElement = allocate_element(list); + newElement->data = value; newElement->next = element; - PListElement* prevElement = element->prev; + prevElement = element->prev; newElement->prev = prevElement; if (prevElement != NULL) { prevElement->next = newElement; @@ -131,10 +95,12 @@ void plist_insert_before(PList* list, PListElement* element, void* value) { } void plist_insert_after(PList* list, PListElement* element, void* value) { + PListElement* nextElement; PListElement* newElement = allocate_element(list); + newElement->data = value; newElement->prev = element; - PListElement* nextElement = element->next; + nextElement = element->next; newElement->next = nextElement; if (nextElement != NULL) { nextElement->prev = newElement; @@ -160,7 +126,7 @@ void plist_erase(PList* list, PListElement* element) { } --list->elementCount; /* Clean the element and prepend it to the free list */ - element->prev = NULL; /* The allocation code exprects prev to be NULL */ + element->prev = NULL; /* The allocation code expects prev to be NULL */ element->next = list->firstFreeElement; list->firstFreeElement = element; }