summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2004-11-01 10:40:38 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2004-11-01 10:40:38 +0100
commit0b62aff0e3385ed0c11fda145c2a5167bbc1c56d (patch)
tree6067296e3f76b842a59919c3453a45c83538ad97 /tools.c
parentc88e65b6385a9c72778ea46fe4c4c805976c7b96 (diff)
downloadvdr-0b62aff0e3385ed0c11fda145c2a5167bbc1c56d.tar.gz
vdr-0b62aff0e3385ed0c11fda145c2a5167bbc1c56d.tar.bz2
Now using qsort() to sort cListBase lists
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/tools.c b/tools.c
index 0f42182e..ecb57c31 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.80 2004/06/13 14:36:41 kls Exp $
+ * $Id: tools.c 1.81 2004/10/31 16:42:36 kls Exp $
*/
#include "tools.h"
@@ -939,19 +939,28 @@ int cListBase::Count(void) const
return n;
}
+static int CompareListObjects(const void *a, const void *b)
+{
+ const cListObject *la = *(const cListObject **)a;
+ const cListObject *lb = *(const cListObject **)b;
+ return la->Compare(*lb);
+}
+
void cListBase::Sort(void)
{
- bool swapped;
- do {
- swapped = false;
- cListObject *object = objects;
- while (object) {
- if (object->Next() && *object->Next() < *object) {
- Move(object->Next(), object);
- swapped = true;
- }
- object = object->Next();
- }
- } while (swapped);
+ int n = Count();
+ cListObject *a[n];
+ cListObject *object = objects;
+ int i = 0;
+ while (object && i < n) {
+ a[i++] = object;
+ object = object->Next();
+ }
+ qsort(a, n, sizeof(cListObject *), CompareListObjects);
+ objects = lastObject = NULL;
+ for (i = 0; i < n; i++) {
+ a[i]->Unlink();
+ Add(a[i]);
+ }
}