kwo pushed a commit to branch master.

commit 1d2dd98f980eebbb9fe67aeb13e126b4d40fc169
Author: Kim Woelders <[email protected]>
Date:   Wed Oct 27 18:21:55 2010 +0200

    Eliminate Quicksort(), use libc qsort() in stead.
    
    Might as well use libc function - saves some bytes of code.
---
 src/E.h           |  5 ----
 src/backgrounds.c |  8 +++----
 src/ipc.c         |  4 ++--
 src/menus-misc.c  |  8 +++----
 src/misc.c        | 72 +------------------------------------------------------
 5 files changed, 11 insertions(+), 86 deletions(-)

diff --git a/src/E.h b/src/E.h
index ae47222..b336870 100644
--- a/src/E.h
+++ b/src/E.h
@@ -549,11 +549,6 @@ __NORETURN__ void   EExit(int exitcode);
 
 void                Etmp(char *s);
 
-/* misc.c */
-void                Quicksort(void **a, int l, int r,
-                             int (*CompareFunc) (const void *d1,
-                                                 const void *d2));
-
 /* mod-misc.c */
 void                autosave(void);
 
diff --git a/src/backgrounds.c b/src/backgrounds.c
index 1a5e1bb..b6baf3d 100644
--- a/src/backgrounds.c
+++ b/src/backgrounds.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various 
contributors
- * Copyright (C) 2004-2012 Kim Woelders
+ * Copyright (C) 2004-2013 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -1860,8 +1860,8 @@ CB_BGNext(Dialog * d __UNUSED__, int val, void *data 
__UNUSED__)
 static int
 BG_SortFileCompare(const void *_bg1, const void *_bg2)
 {
-   const Background   *bg1 = (const Background *)_bg1;
-   const Background   *bg2 = (const Background *)_bg2;
+   const Background   *bg1 = *(const Background **)_bg1;
+   const Background   *bg2 = *(const Background **)_bg2;
    const char         *name1, *name2;
 
    /* return < 0 is b1 <  b2 */
@@ -1892,7 +1892,7 @@ CB_BGSortFile(Dialog * d __UNUSED__, int val __UNUSED__, 
void *data __UNUSED__)
    /* remove them all from the list */
    for (i = 0; i < num; i++)
       ecore_list_node_remove(bg_list, bglist[i]);
-   Quicksort((void **)bglist, 0, num - 2, BG_SortFileCompare);
+   qsort(bglist, num - 1, sizeof(Background *), BG_SortFileCompare);
    for (i = 0; i < num; i++)
       ecore_list_append(bg_list, bglist[i]);
    Efree(bglist);
diff --git a/src/ipc.c b/src/ipc.c
index 6fe1656..0a08353 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -1802,7 +1802,7 @@ EFuncDefer(EWin * ewin, const char *cmd)
 static int
 ipccmp(const void *p1, const void *p2)
 {
-   return strcmp(((const IpcItem *)p1)->name, ((const IpcItem *)p2)->name);
+   return strcmp((*(const IpcItem **)p1)->name, (*(const IpcItem **)p2)->name);
 }
 
 static void
@@ -1822,7 +1822,7 @@ IPC_Help(const char *params)
                    "Use \"help <command>\" for an individual 
description\n\n"));
        IpcPrintf(_("Commands currently available:\n"));
 
-       Quicksort((void **)lst, 0, num - 1, ipccmp);
+       qsort(lst, num, sizeof(IpcItem *), ipccmp);
 
        for (i = 0; i < num; i++)
          {
diff --git a/src/menus-misc.c b/src/menus-misc.c
index 8ddfebe..9c515d2 100644
--- a/src/menus-misc.c
+++ b/src/menus-misc.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various 
contributors
- * Copyright (C) 2004-2011 Kim Woelders
+ * Copyright (C) 2004-2013 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -463,8 +463,8 @@ static int
 BorderNameCompare(const void *b1, const void *b2)
 {
    if (b1 && b2)
-      return strcmp(BorderGetName((const Border *)b1),
-                   BorderGetName((const Border *)b2));
+      return strcmp(BorderGetName(*(const Border **)b1),
+                   BorderGetName(*(const Border **)b2));
 
    return 0;
 }
@@ -485,7 +485,7 @@ MenuCreateFromBorders(const char *name, MenuStyle * ms)
    if (!lst)
       return m;
 
-   Quicksort((void **)lst, 0, num - 1, BorderNameCompare);
+   qsort(lst, num, sizeof(Border *), BorderNameCompare);
    for (i = 0; i < num; i++)
      {
        /* if its not internal (ie doesnt start with _ ) */
diff --git a/src/misc.c b/src/misc.c
index 78dc8a3..9552eb5 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various 
contributors
- * Copyright (C) 2004-2012 Kim Woelders
+ * Copyright (C) 2004-2013 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -27,76 +27,6 @@
 #include <sys/time.h>
 #include <time.h>
 
-/* This is a general quicksort algorithm, using median-of-three strategy.
- * 
- * Parameters:
- * ===========
- * a:            array of items to be sorted (list of void pointers).
- * l:            left edge of sub-array to be sorted. Toplevel call has 0 here.
- * r:            right edge of sub-array to be sorted. Toplevel call has |a| - 
1 here.
- * CompareFunc:  Pointer to a function that accepts two general items d1 and d2
- * and returns values as follows:
- * 
- * < 0  --> d1 "smaller" than d2
- * > 0  --> d1 "larger"  than d2
- * 0    --> d1 "==" d2.
- * 
- * See sample application in ipc.c's IPC_Help.
- */
-void
-Quicksort(void **a, int l, int r,
-         int (*CompareFunc) (const void *d1, const void *d2))
-{
-   int                 i, j, m;
-   void               *v, *t;
-
-   if (r > l)
-     {
-
-       m = (r + l) / 2 + 1;
-       if (CompareFunc(a[l], a[r]) > 0)
-         {
-            t = a[l];
-            a[l] = a[r];
-            a[r] = t;
-         }
-       if (CompareFunc(a[l], a[m]) > 0)
-         {
-            t = a[l];
-            a[l] = a[m];
-            a[m] = t;
-         }
-       if (CompareFunc(a[r], a[m]) > 0)
-         {
-            t = a[r];
-            a[r] = a[m];
-            a[m] = t;
-         }
-
-       v = a[r];
-       i = l - 1;
-       j = r;
-
-       for (;;)
-         {
-            while (CompareFunc(a[++i], v) < 0)
-               ;
-            while (CompareFunc(a[--j], v) > 0)
-               ;
-            if (i >= j)
-               break;
-            t = a[i];
-            a[i] = a[j];
-            a[j] = t;
-         }
-       t = a[i];
-       a[i] = a[r];
-       a[r] = t;
-       Quicksort(a, l, i - 1, CompareFunc);
-       Quicksort(a, i + 1, r, CompareFunc);
-     }
-}
-
 /*
  * Debug/error message printing.
  */

-- 

------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2

Reply via email to