]> git.gag.com Git - fw/sdcc/commitdiff
replace bubble sorts (believe it or not) with qsort calls
authorkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Sep 2000 22:13:21 +0000 (22:13 +0000)
committerkvigor <kvigor@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Sep 2000 22:13:21 +0000 (22:13 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@393 4a8a32a2-be11-0410-ad9d-d568d2c75423

as/mcs51/aslist.c
as/mcs51/lklist.c

index 3288c18f460b80888162183b19e27f6acf4507d9..4d03fc2a971367bb2f23d68df9df3f03792a0da9 100644 (file)
@@ -16,6 +16,7 @@
 #include <setjmp.h>
 #include <string.h>
 #include <alloc.h>
+#include <stdlib.h>
 #include "asm.h"
 
 /*)Module      aslist.c
@@ -477,6 +478,14 @@ int flag;
        }
 }
 
+/* Used for qsort call in lstsym */
+static int _cmpSym(const void *p1, const void *p2)
+{
+    struct sym **s1 = (struct sym **)(p1);
+    struct sym **s2 = (struct sym **)(p2);
+    return strcmp((*s1)->s_id,(*s2)->s_id);
+}
+
 /*)Function    VOID    lstsym(fp)
  *
  *             FILE *  fp              file handle for output
@@ -573,6 +582,8 @@ FILE *fp;
                }
        }
 
+#if 0
+       /* BUBBLE SORT?? WTF??? */
        /*
         * Bubble Sort on Symbol Table Array
         */
@@ -589,6 +600,10 @@ FILE *fp;
                        }
                }
        }
+#else
+
+       qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
+#endif 
 
        /*
         * Symbol Table Output
index 5ac3f07b6a70d85f8c078af62989593878f186b2..31f134232929f42ca526e666bf08f407163a001f 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <alloc.h>
+#include <stdlib.h>
 #include "aslink.h"
 
 /*)Module      lklist.c
@@ -116,6 +117,23 @@ FILE *fp;
        lop = 1;
 }
 
+/* Used for qsort call in lstsym */
+static int _cmpSymByAddr(const void *p1, const void *p2)
+{
+    struct sym **s1 = (struct sym **)(p1);
+    struct sym **s2 = (struct sym **)(p2);
+    int delta = ((*s1)->s_addr + (*s1)->s_axp->a_addr) -
+               ((*s2)->s_addr + (*s2)->s_axp->a_addr);
+
+    /* Sort first by address, then by name. */
+    if (delta)
+    {
+       return delta;
+    }
+    return strcmp((*s1)->s_id,(*s2)->s_id);    
+}
+
+
 #if    NCPS-8
 
 /* NCPS != 8 */
@@ -167,10 +185,12 @@ lstarea(xp)
 struct area *xp;
 {
        register struct areax *oxp;
-       register int i, j;
+       register int i;
+       /* int j; */
        register char *ptr;
        int nmsym;
-       addr_t a0, ai, aj;
+       /* addr_t a0; */
+       addr_t     ai, aj;
        struct sym *sp;
        struct sym **p;
        int memPage;
@@ -289,6 +309,7 @@ struct area *xp;
                oxp = oxp->a_axp;
        }
 
+#if 0
        /*
         * Bubble Sort of Addresses in Symbol Table Array
         */
@@ -308,6 +329,9 @@ struct area *xp;
                        a0 = ai;
                }
        }
+#else
+       qsort(p, nmsym, sizeof(struct sym *), _cmpSymByAddr);
+#endif 
 
        /*
         * Symbol Table Output
@@ -521,6 +545,7 @@ struct area *xp;
                oxp = oxp->a_axp;
        }
 
+#if 0
        /*
         * Bubble Sort of Addresses in Symbol Table Array
         */
@@ -540,6 +565,9 @@ struct area *xp;
                        a0 = ai;
                }
        }
+#else
+       qsort(p, nmsym, sizeof(struct sym *), _cmpSymByAddr);
+#endif 
 
        /*
         * Symbol Table Output