develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34691 - trunk/src

From:
petdance
Date:
December 31, 2008 00:19
Subject:
[svn:parrot] r34691 - trunk/src
Message ID:
20081231081857.32151CB9FA@x12.develooper.com
Author: petdance
Date: Wed Dec 31 00:18:56 2008
New Revision: 34691

Modified:
   trunk/src/utils.c

Log:
Removed the swap() function from the sort.  Call me a premature optimizer, but I think it's safe to inline three swap calls.

Modified: trunk/src/utils.c
==============================================================================
--- trunk/src/utils.c	(original)
+++ trunk/src/utils.c	Wed Dec 31 00:18:56 2008
@@ -69,12 +69,6 @@
     ARGIN(parrot_prm_context* c))
         __attribute__nonnull__(2);
 
-static void swap(ARGMOD(void **x), ARGMOD(void **y))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*x)
-        FUNC_MODIFIES(*y);
-
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
@@ -849,17 +843,9 @@
     mem_sys_free(backup);
 }
 
-/* TODO: Macroize swap and COMPARE */
-static void
-swap(ARGMOD(void **x), ARGMOD(void **y))
-{
-    void *t = *x;
-    *x      = *y;
-    *y      =  t;
-}
-
 typedef INTVAL (*sort_func_t)(PARROT_INTERP, void *, void *);
 
+/* TODO: Macroize COMPARE */
 static INTVAL
 COMPARE(PARROT_INTERP, ARGIN(void *a), ARGIN(void *b), ARGIN(PMC *cmp))
 {
@@ -880,13 +866,16 @@
 {
     while (n > 1) {
         UINTVAL i, j, ln, rn;
+        void *temp;
 
-        swap(&data[0], &data[n / 2]);
+        /* Swap */
+        temp      = data[0];
+        data[0]   = data[n/2];
+        data[n/2] = temp;
 
         for (i = 0, j = n; ;) {
             do
                 --j;
-
             while (j > 0 && COMPARE(interp, data[j], data[0], cmp) > 0);
 
             do
@@ -896,10 +885,16 @@
             if (i >= j)
                 break;
 
-            swap(&data[i], &data[j]);
+            /* Swap */
+            temp    = data[i];
+            data[i] = data[j];
+            data[j] = temp;
         }
 
-        swap(&data[j], &data[0]);
+        /* Swap */
+        temp    = data[j];
+        data[j] = data[0];
+        data[0] = temp;
 
         ln = j;
         rn = n - ++j;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About