Introduced cListBase::count for better performance

This commit is contained in:
Klaus Schmidinger 2005-05-26 11:41:33 +02:00
parent 373c69043a
commit 1855ab0ef3
4 changed files with 12 additions and 15 deletions

View File

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

View File

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

20
tools.c
View File

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

View File

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