From: Peep P. <so...@us...> - 2004-06-14 20:57:33
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22682 Modified Files: list.c Log Message: A little change in list_push. Index: list.c =================================================================== RCS file: /cvsroot/agd/server/src/list.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- list.c 8 Jun 2004 20:44:53 -0000 1.8 +++ list.c 14 Jun 2004 20:57:24 -0000 1.9 @@ -2,13 +2,6 @@ list.c - a generic linked list data structure Based on (the old) array.c -solicit 06.12.03 - - XXX - this could be a lot faster if we wouldn't - start from the beginning of the chain to - find an empty slot or then push it into the end, - but just set new element as root, and former - root as ->next in chain - i.e. reverse the order. - Look into it. */ #include <stdio.h> #include "sys.h" @@ -16,22 +9,16 @@ void list_push(list_t *l, void *data) { - list_t *p; + list_t *p = l; - p = l; - while(p->next != p && p->next) { - if(!p->data) { /* reuse the slot */ - p->data = data; - return; - } - p = p->next; - } - if(!p->data) { - /* reusable slot */ p->data = data; } else { - /* didn't find a reusable slot */ + while(1) { + if(!p->next) + break; + p = p->next; + } p->next = xmalloc(sizeof(list_t)); p = p->next; p->data = data; @@ -49,12 +36,18 @@ while(1) { if(p->data == data) { if(!prev) { - l = p->next; + if(p->next) { + list_t temp; + temp = *p->next; + *p = temp; + } else { + p->data = NULL; + } } else { prev->next = p->next; } /* if(p != saved_l) - xfree(p);*/ /* Never free the root element. */ + free(p);*/ /* Never free the root element. */ return; } prev = p; |