Eliminate Quicksort(), use libc qsort() in stead.

Might as well use libc function - saves some bytes of code.
This commit is contained in:
Kim Woelders 2010-10-27 18:21:55 +02:00
parent 0df373ae77
commit 1d2dd98f98
5 changed files with 11 additions and 86 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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++)
{

View File

@ -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 _ ) */

View File

@ -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.
*/