From 1ee2fb5b4b0af80dd862e063363cf1f30c5534ae Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 13 Apr 2009 17:01:29 +0000 Subject: [PATCH] * sort_msglist() now uses qsort() instead of a bubble sort --- citadel/room_ops.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 8f26845df..e1d501a1c 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -493,6 +493,15 @@ void delete_msglist(struct ctdlroom *whichroom) +/* + * Message pointer compare function for sort_msglist() + */ +int sort_msglist_cmp(long *m1, long *m2) { + if (*m1 > *m2) return(1); + if (*m1 < *m2) return(-1); + return(0); +} + /* * sort message pointers @@ -500,25 +509,15 @@ void delete_msglist(struct ctdlroom *whichroom) */ int sort_msglist(long listptrs[], int oldcount) { - int a, b; - long hold1, hold2; int numitems; numitems = oldcount; - if (numitems < 2) + if (numitems < 2) { return (oldcount); + } /* do the sort */ - for (a = numitems - 2; a >= 0; --a) { - for (b = 0; b <= a; ++b) { - if (listptrs[b] > (listptrs[b + 1])) { - hold1 = listptrs[b]; - hold2 = listptrs[b + 1]; - listptrs[b] = hold2; - listptrs[b + 1] = hold1; - } - } - } + qsort(listptrs, numitems, sizeof(long), sort_msglist_cmp); /* and yank any nulls */ while ((numitems > 0) && (listptrs[0] == 0L)) { -- 2.30.2