From: ticktock35 Date: Mon, 15 Dec 2008 05:32:19 +0000 (+0000) Subject: opkg: refactory active_list_next remove unnecessary field. X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=commitdiff_plain;h=32ee5d15aca5dcdae46084c4a07fb7a072af379a;ds=inline opkg: refactory active_list_next remove unnecessary field. git-svn-id: http://opkg.googlecode.com/svn/trunk@168 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libopkg/active_list.c b/libopkg/active_list.c index b4bbef9..800915d 100644 --- a/libopkg/active_list.c +++ b/libopkg/active_list.c @@ -23,7 +23,6 @@ void active_list_init(struct active_list *ptr) { INIT_LIST_HEAD(&ptr->node); INIT_LIST_HEAD(&ptr->depend); - ptr->walked=0; ptr->depended = NULL; } @@ -31,38 +30,23 @@ void active_list_init(struct active_list *ptr) { */ struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) { struct active_list *next=NULL; - if (!head || !ptr) { + if (!head) { fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr); return NULL; } - if (ptr == head) { - head->walked = !head->walked; - next = list_entry(ptr->node.next, struct active_list, node); - if (next == head) - return NULL; - return active_list_next(head, next); - } - if (ptr->depend.next != &ptr->depend) { - next = list_entry(ptr->depend.next, struct active_list, node); - if (head->walked != next->walked) { - ptr->walked = head->walked; - return active_list_next(head, next); - } - } - if (ptr->walked != head->walked) { - ptr->walked = head->walked; - return ptr; + if (!ptr) + ptr = head; + next = list_entry(ptr->node.next, struct active_list, node); + if (next == head ) { + return NULL; } - - if (ptr->depended && ptr->node.next == &ptr->depended->depend ) { + if (ptr->depended && &ptr->depended->depend == ptr->node.next ) { return ptr->depended; } - - if (ptr->node.next != &head->node) { - next = list_entry(ptr->node.next, struct active_list, node); - return active_list_next(head, next); - } - return NULL; + while (next->depend.next != &next->depend) { + next = list_entry(next->depend.next, struct active_list, node); + } + return next; } @@ -78,4 +62,5 @@ void active_list_add_depend(struct active_list *node, struct active_list *depend void active_list_add(struct active_list *head, struct active_list *node) { list_del_init(&node->node); list_add_tail(&node->node, &head->node); + node->depended = head; } diff --git a/libopkg/active_list.h b/libopkg/active_list.h index a32070f..79ab77d 100644 --- a/libopkg/active_list.h +++ b/libopkg/active_list.h @@ -23,7 +23,6 @@ struct active_list { struct list_head node; struct list_head depend; - char walked; struct active_list *depended; }; diff --git a/tests/opkg_active_list_test.c b/tests/opkg_active_list_test.c index 88371a2..f7bd390 100644 --- a/tests/opkg_active_list_test.c +++ b/tests/opkg_active_list_test.c @@ -110,7 +110,7 @@ int main (void) { printf ("%s ",test->str); } printf("\n"); - for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) { + for(ptr = active_list_next(&head, NULL); ptr ;ptr = active_list_next(&head, ptr)) { test = list_entry(ptr, struct active_test, list); printf ("%s ",test->str); }