* sort_msglist() now uses qsort() instead of a bubble sort
authorArt Cancro <ajc@citadel.org>
Mon, 13 Apr 2009 17:01:29 +0000 (17:01 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 13 Apr 2009 17:01:29 +0000 (17:01 +0000)
citadel/room_ops.c

index 8f26845dfedf9e86630757eed8d16d0d05f587ae..e1d501a1c4cf7860a4544126136d64de52111303 100644 (file)
@@ -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)) {