summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-12-27 20:24:40 +0100
committerThomas Haller <thaller@redhat.com>2018-01-03 16:02:13 +0100
commitfeeb70ef8928a92c392ad3ef6d032f3df8b125cb (patch)
tree98b42db4f1ad18f87f5005f75d3b08cb1814af89 /shared
parent3a73a15863b8569e0e5b987daed78b93f7c11eb0 (diff)
downloadNetworkManager-feeb70ef8928a92c392ad3ef6d032f3df8b125cb.tar.gz
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.
Diffstat (limited to 'shared')
-rw-r--r--shared/nm-utils/c-list-util.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/shared/nm-utils/c-list-util.c b/shared/nm-utils/c-list-util.c
index 070323c69d..509f4e12ab 100644
--- a/shared/nm-utils/c-list-util.c
+++ b/shared/nm-utils/c-list-util.c
@@ -58,39 +58,35 @@ c_list_relink (CList *lst)
/*****************************************************************************/
static CList *
-_c_list_sort (CList *ls,
- CListSortCmp cmp,
- const void *user_data)
+_c_list_srt_split (CList *ls)
{
- CList *ls1, *ls2;
- CList head;
+ CList *ls2;
- if (!ls->next)
- return ls;
-
- /* split list in two halfs @ls1 and @ls2. */
- ls1 = ls;
ls2 = ls;
ls = ls->next;
- while (ls) {
+ if (!ls)
+ return NULL;
+ do {
ls = ls->next;
if (!ls)
break;
ls = ls->next;
ls2 = ls2->next;
- }
- ls = ls2;
- ls2 = ls->next;
- ls->next = NULL;
-
- /* recurse */
- ls1 = _c_list_sort (ls1, cmp, user_data);
- if (!ls2)
- return ls1;
+ } while (ls);
+ ls = ls2->next;
+ ls2->next = NULL;
+ return ls;
+}
- ls2 = _c_list_sort (ls2, cmp, user_data);
+static CList *
+_c_list_srt_merge (CList *ls1,
+ CList *ls2,
+ CListSortCmp cmp,
+ const void *user_data)
+{
+ CList *ls;
+ CList head;
- /* merge */
ls = &head;
for (;;) {
/* while invoking the @cmp function, the list
@@ -115,6 +111,28 @@ _c_list_sort (CList *ls,
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:
* @lst: the list.