summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2005-05-26 11:41:33 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2005-05-26 11:41:33 +0200
commit1855ab0ef3ff5ef220cbd3bc486b0c4d66063073 (patch)
tree0a651fb83e19f63f5acc96ba50b477e4b0f7b0ed
parent373c69043ae352778974735460753d5e4f500789 (diff)
downloadvdr-1855ab0ef3ff5ef220cbd3bc486b0c4d66063073.tar.gz
vdr-1855ab0ef3ff5ef220cbd3bc486b0c4d66063073.tar.bz2
Introduced cListBase::count for better performance
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY1
-rw-r--r--tools.c20
-rw-r--r--tools.h5
4 files changed, 12 insertions, 15 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 3a1f4c66..cac3fb7a 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -1360,3 +1360,4 @@ Paavo Hartikainen <pahartik@sci.fi>
Georg Acher <acher@baycom.de>
for making tChannelID::operator==() inline for better performance
+ for introducing cListBase::count for better performance
diff --git a/HISTORY b/HISTORY
index 764b7f98..e2912dab 100644
--- a/HISTORY
+++ b/HISTORY
@@ -3565,3 +3565,4 @@ Video Disk Recorder Revision History
Andreas Kool for pointing out that 'vdr --version' failed on an UTF-8 system).
- Made tChannelID::operator==() inline for better performance (thanks to Georg
Acher).
+- Introduced cListBase::count for better performance (thanks to Georg Acher).
diff --git a/tools.c b/tools.c
index 075be185..9e1ea1d0 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.92 2005/05/16 09:55:26 kls Exp $
+ * $Id: tools.c 1.93 2005/05/26 11:40:14 kls Exp $
*/
#include "tools.h"
@@ -932,6 +932,7 @@ int cListObject::Index(void) const
cListBase::cListBase(void)
{
objects = lastObject = NULL;
+ count = 0;
}
cListBase::~cListBase()
@@ -952,6 +953,7 @@ void cListBase::Add(cListObject *Object, cListObject *After)
objects = Object;
lastObject = Object;
}
+ count++;
}
void cListBase::Ins(cListObject *Object, cListObject *Before)
@@ -967,6 +969,7 @@ void cListBase::Ins(cListObject *Object, cListObject *Before)
lastObject = Object;
objects = Object;
}
+ count++;
}
void cListBase::Del(cListObject *Object, bool DeleteObject)
@@ -978,6 +981,7 @@ void cListBase::Del(cListObject *Object, bool DeleteObject)
Object->Unlink();
if (DeleteObject)
delete Object;
+ count--;
}
void cListBase::Move(int From, int To)
@@ -1017,6 +1021,7 @@ void cListBase::Clear(void)
objects = object;
}
objects = lastObject = NULL;
+ count = 0;
}
cListObject *cListBase::Get(int Index) const
@@ -1029,18 +1034,6 @@ cListObject *cListBase::Get(int Index) const
return object;
}
-int cListBase::Count(void) const
-{
- int n = 0;
- cListObject *object = objects;
-
- while (object) {
- n++;
- object = object->Next();
- }
- return n;
-}
-
static int CompareListObjects(const void *a, const void *b)
{
const cListObject *la = *(const cListObject **)a;
@@ -1062,6 +1055,7 @@ void cListBase::Sort(void)
objects = lastObject = NULL;
for (i = 0; i < n; i++) {
a[i]->Unlink();
+ count--;
Add(a[i]);
}
}
diff --git a/tools.h b/tools.h
index 31a88d45..a45facbf 100644
--- a/tools.h
+++ b/tools.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.h 1.69 2005/05/16 09:55:19 kls Exp $
+ * $Id: tools.h 1.70 2005/05/26 11:34:01 kls Exp $
*/
#ifndef __TOOLS_H
@@ -213,6 +213,7 @@ class cListBase {
protected:
cListObject *objects, *lastObject;
cListBase(void);
+ int count;
public:
virtual ~cListBase();
void Add(cListObject *Object, cListObject *After = NULL);
@@ -222,7 +223,7 @@ public:
void Move(cListObject *From, cListObject *To);
virtual void Clear(void);
cListObject *Get(int Index) const;
- int Count(void) const;
+ int Count(void) const { return count; }
void Sort(void);
};