Mercurial > pidgin
changeset 21939:5bf38e411fda
Yes, we really can use qsort(3) rather than reimplementing it. I've tested
this code against some invented 0xffffffff-terminated guint32 arrays and it
sorts them identically to the old code. I'm a little unconvinced by said
0xffffffff-terminated arrays in the first place: someone might like to go
through replacing them with GArrays!
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Tue, 25 Dec 2007 22:59:15 +0000 |
parents | 76d025660d9e |
children | 63ebd65857f8 |
files | libpurple/protocols/qq/group_opt.c |
diffstat | 1 files changed, 6 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/qq/group_opt.c Sat Dec 22 11:40:34 2007 +0000 +++ b/libpurple/protocols/qq/group_opt.c Tue Dec 25 22:59:15 2007 +0000 @@ -39,37 +39,12 @@ #include "packet_parse.h" #include "utils.h" -/* TODO: can't we use qsort here? */ -/* This implement quick sort algorithm (low->high) */ -static void _quick_sort(gint *numbers, gint left, gint right) +static int _compare_guint32(const void *a, + const void *b) { - gint pivot, l_hold, r_hold; - - l_hold = left; - r_hold = right; - pivot = numbers[left]; - while (left < right) { - while ((numbers[right] >= pivot) && (left < right)) - right--; - if (left != right) { - numbers[left] = numbers[right]; - left++; - } - while ((numbers[left] <= pivot) && (left < right)) - left++; - if (left != right) { - numbers[right] = numbers[left]; - right--; - } - } - numbers[left] = pivot; - pivot = left; - left = l_hold; - right = r_hold; - if (left < pivot) - _quick_sort(numbers, left, pivot - 1); - if (right > pivot) - _quick_sort(numbers, pivot + 1, right); + const guint32 *x = a; + const guint32 *y = b; + return (*x - *y); } static void _sort(guint32 *list) @@ -77,7 +52,7 @@ gint i; for (i = 0; list[i] < 0xffffffff; i++) {; } - _quick_sort((gint *) list, 0, i - 1); + qsort (list, i, sizeof (guint32), _compare_guint32); } static void _qq_group_member_opt(PurpleConnection *gc, qq_group *group, gint operation, guint32 *members)