Skip to content
Browse files

make FIA sort method half-usable

git-svn-id: https://svn.parrot.org/parrot/trunk@47535 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 9c48f7d commit 4927d8a6fb66027d2ca7d6fcf6f1f76b240f7294 @NotFound NotFound committed Jun 10, 2010
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/pmc/fixedintegerarray.pmc
View
20 src/pmc/fixedintegerarray.pmc
@@ -21,8 +21,20 @@ INTVALs. It uses Integer PMCs for all of the conversions.
/* 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 @@ Sets the string value of the element at index C<key> to C<value>.
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 @@ Sets the string value of the element at index C<key> to C<value>.
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);
}
}

0 comments on commit 4927d8a

Please sign in to comment.
Something went wrong with that request. Please try again.