[svn:parrot] r47535 - trunk/src/pmc

NotFound at svn.parrot.org NotFound at svn.parrot.org
Thu Jun 10 15:14:02 UTC 2010


Author: NotFound
Date: Thu Jun 10 15:14:01 2010
New Revision: 47535
URL: https://trac.parrot.org/parrot/changeset/47535

Log:
make FIA sort method half-usable

Modified:
   trunk/src/pmc/fixedintegerarray.pmc

Modified: trunk/src/pmc/fixedintegerarray.pmc
==============================================================================
--- trunk/src/pmc/fixedintegerarray.pmc	Thu Jun 10 13:34:22 2010	(r47534)
+++ trunk/src/pmc/fixedintegerarray.pmc	Thu Jun 10 15:14:01 2010	(r47535)
@@ -21,8 +21,20 @@
 
 /* HEADERIZER HFILE: none */
 /* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+
+static int auxcmpfunc(const INTVAL *i, const INTVAL *j);
+#define ASSERT_ARGS_auxcmpfunc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
+static int
+auxcmpfunc(const INTVAL *i, const INTVAL *j)
+{
+    ASSERT_ARGS(auxcmpfunc)
+    return *i - *j;
+}
+
 pmclass FixedIntegerArray auto_attrs provides array {
     ATTR INTVAL   size;  /* number of INTVALs stored in this array */
     ATTR INTVAL * int_array; /* INTVALs are stored here */
@@ -492,7 +504,7 @@
         SELF.set_pmc_keyed_int(k, value);
     }
 
-    METHOD sort(PMC *cmp_func) {
+    METHOD sort(PMC *cmp_func :optional) {
         INTVAL *int_array;
         UINTVAL n;
         INTVAL  size;
@@ -503,7 +515,11 @@
 
         if (n > 1) {
             GET_ATTR_int_array(INTERP, SELF, int_array);
-            Parrot_quicksort(INTERP, (void**)int_array, n, cmp_func);
+            if (PMC_IS_NULL(cmp_func))
+                qsort(int_array, n, sizeof(INTVAL),
+                        (int (*)(const void *, const void*))auxcmpfunc);
+            else
+                Parrot_quicksort(INTERP, (void**)int_array, n, cmp_func);
         }
     }
 


More information about the parrot-commits mailing list