mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 10:38:30 +02:00
shared: split helper functions out of c_list_sort()
Just to make it clearer what happens. The compiler can (and possibly will) inline these static functions just fine.
This commit is contained in:
parent
3a73a15863
commit
feeb70ef89
1 changed files with 40 additions and 22 deletions
|
|
@ -58,39 +58,35 @@ c_list_relink (CList *lst)
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static CList *
|
static CList *
|
||||||
_c_list_sort (CList *ls,
|
_c_list_srt_split (CList *ls)
|
||||||
CListSortCmp cmp,
|
|
||||||
const void *user_data)
|
|
||||||
{
|
{
|
||||||
CList *ls1, *ls2;
|
CList *ls2;
|
||||||
CList head;
|
|
||||||
|
|
||||||
if (!ls->next)
|
|
||||||
return ls;
|
|
||||||
|
|
||||||
/* split list in two halfs @ls1 and @ls2. */
|
|
||||||
ls1 = ls;
|
|
||||||
ls2 = ls;
|
ls2 = ls;
|
||||||
ls = ls->next;
|
ls = ls->next;
|
||||||
while (ls) {
|
if (!ls)
|
||||||
|
return NULL;
|
||||||
|
do {
|
||||||
ls = ls->next;
|
ls = ls->next;
|
||||||
if (!ls)
|
if (!ls)
|
||||||
break;
|
break;
|
||||||
ls = ls->next;
|
ls = ls->next;
|
||||||
ls2 = ls2->next;
|
ls2 = ls2->next;
|
||||||
}
|
} while (ls);
|
||||||
ls = ls2;
|
ls = ls2->next;
|
||||||
ls2 = ls->next;
|
ls2->next = NULL;
|
||||||
ls->next = NULL;
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
/* recurse */
|
static CList *
|
||||||
ls1 = _c_list_sort (ls1, cmp, user_data);
|
_c_list_srt_merge (CList *ls1,
|
||||||
if (!ls2)
|
CList *ls2,
|
||||||
return ls1;
|
CListSortCmp cmp,
|
||||||
|
const void *user_data)
|
||||||
|
{
|
||||||
|
CList *ls;
|
||||||
|
CList head;
|
||||||
|
|
||||||
ls2 = _c_list_sort (ls2, cmp, user_data);
|
|
||||||
|
|
||||||
/* merge */
|
|
||||||
ls = &head;
|
ls = &head;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* while invoking the @cmp function, the list
|
/* while invoking the @cmp function, the list
|
||||||
|
|
@ -115,6 +111,28 @@ _c_list_sort (CList *ls,
|
||||||
return head.next;
|
return head.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CList *
|
||||||
|
_c_list_sort (CList *ls,
|
||||||
|
CListSortCmp cmp,
|
||||||
|
const void *user_data)
|
||||||
|
{
|
||||||
|
CList *ls1, *ls2;
|
||||||
|
|
||||||
|
if (!ls->next)
|
||||||
|
return ls;
|
||||||
|
ls1 = ls;
|
||||||
|
|
||||||
|
ls2 = _c_list_srt_split (ls1);
|
||||||
|
|
||||||
|
ls1 = _c_list_sort (ls1, cmp, user_data);
|
||||||
|
if (!ls2)
|
||||||
|
return ls1;
|
||||||
|
|
||||||
|
ls2 = _c_list_sort (ls2, cmp, user_data);
|
||||||
|
|
||||||
|
return _c_list_srt_merge (ls1, ls2, cmp, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* c_list_sort_headless:
|
* c_list_sort_headless:
|
||||||
* @lst: the list.
|
* @lst: the list.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue