1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Replace various std::map with UNORDERED_MAP + various cleanups

This is part 2 for 5f084cd98d

Other improvements:

* Use the defined ItemGroupList when used
* make Client::checkPrivilege const
* inline some trivial functions
* Add ActiveObjectMap typedef
* Add SettingsEntries typedef
This commit is contained in:
Loic Blot 2016-10-05 09:03:55 +02:00 committed by Ner'zhul
parent 5f084cd98d
commit 613797a304
23 changed files with 110 additions and 167 deletions

View file

@ -605,11 +605,8 @@ ClientInterface::~ClientInterface()
{
MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator
i = m_clients.begin();
i != m_clients.end(); ++i)
{
for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
// Delete client
delete i->second;
}
@ -621,10 +618,8 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
std::vector<u16> reply;
MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator
i = m_clients.begin();
i != m_clients.end(); ++i)
{
for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
if (i->second->getState() >= min_state)
reply.push_back(i->second->peer_id);
}
@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum,
NetworkPacket* pkt, bool reliable)
{
MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator
i = m_clients.begin();
for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
RemoteClient *client = i->second;
@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum,
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
{
MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if(n == m_clients.end())
if (n == m_clients.end())
return NULL;
if (n->second->getState() >= state_min)
@ -720,11 +713,10 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
{
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if(n == m_clients.end())
if (n == m_clients.end())
return NULL;
if (n->second->getState() >= state_min)
@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
ClientState ClientInterface::getClientState(u16 peer_id)
{
MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if(n == m_clients.end())
if (n == m_clients.end())
return CS_Invalid;
return n->second->getState();
@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id)
void ClientInterface::setPlayerName(u16 peer_id,std::string name)
{
MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if(n != m_clients.end())
if (n != m_clients.end())
n->second->setName(name);
}
@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);
// Error check
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if(n == m_clients.end())
if (n == m_clients.end())
return;
/*
@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);
// Error check
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// The client shouldn't already exist
if(n != m_clients.end()) return;
if (n != m_clients.end()) return;
// Create client
RemoteClient *client = new RemoteClient();
@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
MutexAutoLock clientlock(m_clients_mutex);
// Error check
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// No client to deliver event
if (n == m_clients.end())
@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);
// Error check
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// No client to get version
if (n == m_clients.end())
@ -851,8 +837,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
MutexAutoLock conlock(m_clients_mutex);
// Error check
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
// No client to set versions
if (n == m_clients.end())