Eradicate grub_list_insert

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-03-26 20:00:06 +01:00
parent fda282327f
commit 82f542016e
2 changed files with 14 additions and 27 deletions

View file

@ -36,8 +36,6 @@ typedef int (*grub_list_test_t) (grub_list_t new_item, grub_list_t item);
void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item); void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item);
void * EXPORT_FUNC(grub_list_pop) (grub_list_t *head); void * EXPORT_FUNC(grub_list_pop) (grub_list_t *head);
void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item); void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item);
void EXPORT_FUNC(grub_list_insert) (grub_list_t *head, grub_list_t item,
grub_list_test_t test);
#define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next) #define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)

View file

@ -53,20 +53,6 @@ grub_list_remove (grub_list_t *head, grub_list_t item)
} }
} }
void
grub_list_insert (grub_list_t *head, grub_list_t item,
grub_list_test_t test)
{
grub_list_t *p, q;
for (p = head, q = *p; q; p = &(q->next), q = q->next)
if (test (item, q))
break;
*p = item;
item->next = q;
}
void * void *
grub_named_list_find (grub_named_list_t head, const char *name) grub_named_list_find (grub_named_list_t head, const char *name)
{ {
@ -84,27 +70,30 @@ grub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem)
{ {
int inactive = 0; int inactive = 0;
auto int test (grub_prio_list_t new_item, grub_prio_list_t item); grub_prio_list_t *p, q;
int test (grub_prio_list_t new_item, grub_prio_list_t item)
for (p = head, q = *p; q; p = &(q->next), q = q->next)
{ {
int r; int r;
r = grub_strcmp (new_item->name, item->name); r = grub_strcmp (nitem->name, q->name);
if (r) if (r < 0)
return (r < 0); break;
if (r > 0)
continue;
if (new_item->prio >= (item->prio & GRUB_PRIO_LIST_PRIO_MASK)) if (nitem->prio >= (q->prio & GRUB_PRIO_LIST_PRIO_MASK))
{ {
item->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE; q->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE;
return 1; break;
} }
inactive = 1; inactive = 1;
return 0;
} }
grub_list_insert (GRUB_AS_LIST_P (head), GRUB_AS_LIST (nitem), *p = nitem;
(grub_list_test_t) test); nitem->next = q;
if (! inactive) if (! inactive)
nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE; nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE;
} }