Implement the same PLT reduction technique used in GTK+:
[platform/upstream/glib.git] / glib / gqsort.c
index 040be79..ac45e8b 100644 (file)
  * at ftp://ftp.gtk.org/pub/gtk/.
  */
 
+#include "config.h"
+
 #include <string.h>
 
+#include "galias.h"
 #include "glib.h"
 
+
 /* Byte-wise swap two items of size SIZE. */
 #define SWAP(a, b, size)                                                     \
   do                                                                         \
@@ -108,7 +112,7 @@ stack_node;
 void
 g_qsort_with_data (gconstpointer    pbase,
                   gint             total_elems,
-                  size_t           size,
+                  gsize            size,
                   GCompareDataFunc compare_func,
                   gpointer         user_data)
 {
@@ -120,10 +124,13 @@ g_qsort_with_data (gconstpointer    pbase,
   char *pivot_buffer = (char *) g_alloca (size);
   const size_t max_thresh = MAX_THRESH * size;
 
-  g_return_if_fail (total_elems > 0);
-  g_return_if_fail (pbase != NULL);
+  g_return_if_fail (total_elems >= 0);
+  g_return_if_fail (pbase != NULL || total_elems == 0);
   g_return_if_fail (compare_func != NULL);
 
+  if (total_elems == 0)
+    return;
+
   if (total_elems > MAX_THRESH)
     {
       char *lo = base_ptr;