# HG changeset patch # User Will Thompson # Date 1198623555 0 # Node ID 5bf38e411fda37a9e8782a9af96311e661fcc923 # Parent 76d025660d9ee9ed2dac10ed983b53d913fcfd47 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! diff -r 76d025660d9e -r 5bf38e411fda libpurple/protocols/qq/group_opt.c --- 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)