im.pidgin.pidgin: d56abb1283e79d4ca866e8cf22e0d30e13145e7a

resiak at soc.pidgin.im resiak at soc.pidgin.im
Tue Dec 25 18:05:43 EST 2007


-----------------------------------------------------------------
Revision: d56abb1283e79d4ca866e8cf22e0d30e13145e7a
Ancestor: 10d3d59c0380562be84f687ad42dba6f7e3b8f44
Author: resiak at soc.pidgin.im
Date: 2007-12-25T22:59:15
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/qq/group_opt.c

ChangeLog: 

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!

-------------- next part --------------
============================================================
--- libpurple/protocols/qq/group_opt.c	6b14362a02a9e4d5bb580d7c84e6f71d2b67c7aa
+++ libpurple/protocols/qq/group_opt.c	0ba1e8d92dde92c2644b4e47e4c4e39a9d8564f4
@@ -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 @@ static void _sort(guint32 *list)
 	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)


More information about the Commits mailing list