ClientList: use class boost::intrusive::list

Eliminate extra allocations for the std::list node instances.
This commit is contained in:
Max Kellermann
2014-06-10 18:57:30 +02:00
parent 0801b3f495
commit 3364c1b893
4 changed files with 25 additions and 29 deletions

View File

@@ -20,21 +20,21 @@
#ifndef MPD_CLIENT_LIST_HXX
#define MPD_CLIENT_LIST_HXX
#include <list>
#include "Client.hxx"
class Client;
class ClientList {
typedef std::list<Client *> List;
typedef boost::intrusive::list<Client,
boost::intrusive::constant_time_size<true>> List;
const unsigned max_size;
unsigned size;
List list;
public:
ClientList(unsigned _max_size)
:max_size(_max_size), size(0) {}
:max_size(_max_size) {}
~ClientList() {
CloseAll();
}
@@ -48,12 +48,11 @@ public:
}
bool IsFull() const {
return size >= max_size;
return list.size() >= max_size;
}
void Add(Client &client) {
list.push_front(&client);
++size;
list.push_front(client);
}
void Remove(Client &client);