From 1556f377ecc7c3d4887f8e9f2805a4e7f7e60660 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Wed, 26 Mar 2014 10:56:31 +0100 Subject: [PATCH] media: sort candidates in sipe-media.c With this change we have only a single place where we do the sorting and can avoid unnecessary list copies. --- src/core/sdpmsg.c | 22 ---------------------- src/core/sipe-media.c | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/core/sdpmsg.c b/src/core/sdpmsg.c index 84801ca0..95477a2b 100644 --- a/src/core/sdpmsg.c +++ b/src/core/sdpmsg.c @@ -414,19 +414,6 @@ base64_unpad(const gchar *str) return result; } -static gint -candidate_sort_cb(struct sdpcandidate *c1, struct sdpcandidate *c2) -{ - int cmp = sipe_strcompare(c1->foundation, c2->foundation); - if (cmp == 0) { - cmp = sipe_strcompare(c1->username, c2->username); - if (cmp == 0) - cmp = c1->component - c2->component; - } - - return cmp; -} - static gchar * candidates_to_string(GSList *candidates, SipeIceVersion ice_version) { @@ -434,9 +421,6 @@ candidates_to_string(GSList *candidates, SipeIceVersion ice_version) GSList *i; GSList *processed_tcp_candidates = NULL; - candidates = g_slist_copy(candidates); - candidates = g_slist_sort(candidates, (GCompareFunc)candidate_sort_cb); - for (i = candidates; i; i = i->next) { struct sdpcandidate *c = i->data; const gchar *protocol; @@ -555,7 +539,6 @@ candidates_to_string(GSList *candidates, SipeIceVersion ice_version) } } - g_slist_free(candidates); g_slist_free(processed_tcp_candidates); return g_string_free(result, FALSE); @@ -566,9 +549,6 @@ remote_candidates_to_string(GSList *candidates, SipeIceVersion ice_version) { GString *result = g_string_new(""); - candidates = g_slist_copy(candidates); - candidates = g_slist_sort(candidates, (GCompareFunc)candidate_sort_cb); - if (candidates) { if (ice_version == SIPE_ICE_RFC_5245) { GSList *i; @@ -588,8 +568,6 @@ remote_candidates_to_string(GSList *candidates, SipeIceVersion ice_version) } } - g_slist_free(candidates); - return g_string_free(result, FALSE); } diff --git a/src/core/sipe-media.c b/src/core/sipe-media.c index 6bfd1cbb..cce76c50 100644 --- a/src/core/sipe-media.c +++ b/src/core/sipe-media.c @@ -100,6 +100,19 @@ sipe_media_call_free(struct sipe_media_call_private *call_private) } } +static gint +candidate_sort_cb(struct sdpcandidate *c1, struct sdpcandidate *c2) +{ + int cmp = sipe_strcompare(c1->foundation, c2->foundation); + if (cmp == 0) { + cmp = sipe_strcompare(c1->username, c2->username); + if (cmp == 0) + cmp = c1->component - c2->component; + } + + return cmp; +} + static GSList * backend_candidates_to_sdpcandidate(GList *candidates) { @@ -122,7 +135,8 @@ backend_candidates_to_sdpcandidate(GList *candidates) c->username = sipe_backend_candidate_get_username(candidate); c->password = sipe_backend_candidate_get_password(candidate); - result = g_slist_append(result, c); + result = g_slist_insert_sorted(result, c, + (GCompareFunc)candidate_sort_cb); } return result; -- 2.11.4.GIT