diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3a1f4c66..cac3fb7a 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1360,3 +1360,4 @@ Paavo Hartikainen Georg Acher 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); };