From: kvigor Date: Wed, 20 Sep 2000 22:13:21 +0000 (+0000) Subject: replace bubble sorts (believe it or not) with qsort calls X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=99655d8de9b289946c091484978cb16ea7e2cc53;p=fw%2Fsdcc replace bubble sorts (believe it or not) with qsort calls git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@393 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/as/mcs51/aslist.c b/as/mcs51/aslist.c index 3288c18f..4d03fc2a 100644 --- a/as/mcs51/aslist.c +++ b/as/mcs51/aslist.c @@ -16,6 +16,7 @@ #include #include #include +#include #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 diff --git a/as/mcs51/lklist.c b/as/mcs51/lklist.c index 5ac3f07b..31f13423 100644 --- a/as/mcs51/lklist.c +++ b/as/mcs51/lklist.c @@ -18,6 +18,7 @@ #include #include #include +#include #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