Skip to content

Commit 613797a

Browse files
committedOct 5, 2016
Replace various std::map with UNORDERED_MAP + various cleanups
This is part 2 for 5f084cd Other improvements: * Use the defined ItemGroupList when used * make Client::checkPrivilege const * inline some trivial functions * Add ActiveObjectMap typedef * Add SettingsEntries typedef
1 parent 5f084cd commit 613797a

23 files changed

+110
-167
lines changed
 

Diff for: ‎src/client.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Client::~Client()
303303
delete m_inventory_from_server;
304304

305305
// Delete detached inventories
306-
for (std::map<std::string, Inventory*>::iterator
306+
for (UNORDERED_MAP<std::string, Inventory*>::iterator
307307
i = m_detached_inventories.begin();
308308
i != m_detached_inventories.end(); ++i) {
309309
delete i->second;
@@ -1437,7 +1437,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
14371437
break;
14381438
case InventoryLocation::DETACHED:
14391439
{
1440-
if(m_detached_inventories.count(loc.name) == 0)
1440+
if (m_detached_inventories.count(loc.name) == 0)
14411441
return NULL;
14421442
return m_detached_inventories[loc.name];
14431443
}

Diff for: ‎src/client.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
462462
u16 getHP();
463463
u16 getBreath();
464464

465-
bool checkPrivilege(const std::string &priv)
465+
bool checkPrivilege(const std::string &priv) const
466466
{ return (m_privileges.count(priv) != 0); }
467467

468468
bool getChatMessage(std::wstring &message);
@@ -670,11 +670,11 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
670670
std::map<int, u16> m_sounds_to_objects;
671671

672672
// Privileges
673-
std::set<std::string> m_privileges;
673+
UNORDERED_SET<std::string> m_privileges;
674674

675675
// Detached inventories
676676
// key = name
677-
std::map<std::string, Inventory*> m_detached_inventories;
677+
UNORDERED_MAP<std::string, Inventory*> m_detached_inventories;
678678

679679
// Storage for mesh data for creating multiple instances of the same mesh
680680
StringMap m_mesh_data;

Diff for: ‎src/clientiface.cpp

+20-35
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,8 @@ ClientInterface::~ClientInterface()
605605
{
606606
MutexAutoLock clientslock(m_clients_mutex);
607607

608-
for(std::map<u16, RemoteClient*>::iterator
609-
i = m_clients.begin();
610-
i != m_clients.end(); ++i)
611-
{
612-
608+
for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
609+
i != m_clients.end(); ++i) {
613610
// Delete client
614611
delete i->second;
615612
}
@@ -621,10 +618,8 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
621618
std::vector<u16> reply;
622619
MutexAutoLock clientslock(m_clients_mutex);
623620

624-
for(std::map<u16, RemoteClient*>::iterator
625-
i = m_clients.begin();
626-
i != m_clients.end(); ++i)
627-
{
621+
for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
622+
i != m_clients.end(); ++i) {
628623
if (i->second->getState() >= min_state)
629624
reply.push_back(i->second->peer_id);
630625
}
@@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum,
691686
NetworkPacket* pkt, bool reliable)
692687
{
693688
MutexAutoLock clientslock(m_clients_mutex);
694-
for(std::map<u16, RemoteClient*>::iterator
695-
i = m_clients.begin();
689+
for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
696690
i != m_clients.end(); ++i) {
697691
RemoteClient *client = i->second;
698692

@@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum,
705699
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
706700
{
707701
MutexAutoLock clientslock(m_clients_mutex);
708-
std::map<u16, RemoteClient*>::iterator n;
709-
n = m_clients.find(peer_id);
702+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
710703
// The client may not exist; clients are immediately removed if their
711704
// access is denied, and this event occurs later then.
712-
if(n == m_clients.end())
705+
if (n == m_clients.end())
713706
return NULL;
714707

715708
if (n->second->getState() >= state_min)
@@ -720,11 +713,10 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
720713

721714
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
722715
{
723-
std::map<u16, RemoteClient*>::iterator n;
724-
n = m_clients.find(peer_id);
716+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
725717
// The client may not exist; clients are immediately removed if their
726718
// access is denied, and this event occurs later then.
727-
if(n == m_clients.end())
719+
if (n == m_clients.end())
728720
return NULL;
729721

730722
if (n->second->getState() >= state_min)
@@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
736728
ClientState ClientInterface::getClientState(u16 peer_id)
737729
{
738730
MutexAutoLock clientslock(m_clients_mutex);
739-
std::map<u16, RemoteClient*>::iterator n;
740-
n = m_clients.find(peer_id);
731+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
741732
// The client may not exist; clients are immediately removed if their
742733
// access is denied, and this event occurs later then.
743-
if(n == m_clients.end())
734+
if (n == m_clients.end())
744735
return CS_Invalid;
745736

746737
return n->second->getState();
@@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id)
749740
void ClientInterface::setPlayerName(u16 peer_id,std::string name)
750741
{
751742
MutexAutoLock clientslock(m_clients_mutex);
752-
std::map<u16, RemoteClient*>::iterator n;
753-
n = m_clients.find(peer_id);
743+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
754744
// The client may not exist; clients are immediately removed if their
755745
// access is denied, and this event occurs later then.
756-
if(n != m_clients.end())
746+
if (n != m_clients.end())
757747
n->second->setName(name);
758748
}
759749

@@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id)
762752
MutexAutoLock conlock(m_clients_mutex);
763753

764754
// Error check
765-
std::map<u16, RemoteClient*>::iterator n;
766-
n = m_clients.find(peer_id);
755+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
767756
// The client may not exist; clients are immediately removed if their
768757
// access is denied, and this event occurs later then.
769-
if(n == m_clients.end())
758+
if (n == m_clients.end())
770759
return;
771760

772761
/*
@@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id)
797786
MutexAutoLock conlock(m_clients_mutex);
798787

799788
// Error check
800-
std::map<u16, RemoteClient*>::iterator n;
801-
n = m_clients.find(peer_id);
789+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
802790
// The client shouldn't already exist
803-
if(n != m_clients.end()) return;
791+
if (n != m_clients.end()) return;
804792

805793
// Create client
806794
RemoteClient *client = new RemoteClient();
@@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
814802
MutexAutoLock clientlock(m_clients_mutex);
815803

816804
// Error check
817-
std::map<u16, RemoteClient*>::iterator n;
818-
n = m_clients.find(peer_id);
805+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
819806

820807
// No client to deliver event
821808
if (n == m_clients.end())
@@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
836823
MutexAutoLock conlock(m_clients_mutex);
837824

838825
// Error check
839-
std::map<u16, RemoteClient*>::iterator n;
840-
n = m_clients.find(peer_id);
826+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
841827

842828
// No client to get version
843829
if (n == m_clients.end())
@@ -851,8 +837,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
851837
MutexAutoLock conlock(m_clients_mutex);
852838

853839
// Error check
854-
std::map<u16, RemoteClient*>::iterator n;
855-
n = m_clients.find(peer_id);
840+
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
856841

857842
// No client to set versions
858843
if (n == m_clients.end())

Diff for: ‎src/clientiface.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include "serialization.h" // for SER_FMT_VER_INVALID
2626
#include "threading/mutex.h"
2727
#include "network/networkpacket.h"
28+
#include "util/cpp11_container.h"
2829

2930
#include <list>
3031
#include <vector>
31-
#include <map>
3232
#include <set>
3333

3434
class MapBlock;
@@ -502,8 +502,7 @@ class ClientInterface {
502502
void lock() { m_clients_mutex.lock(); }
503503
void unlock() { m_clients_mutex.unlock(); }
504504

505-
std::map<u16, RemoteClient*>& getClientList()
506-
{ return m_clients; }
505+
UNORDERED_MAP<u16, RemoteClient*>& getClientList() { return m_clients; }
507506

508507
private:
509508
/* update internal player list */
@@ -513,7 +512,7 @@ class ClientInterface {
513512
con::Connection* m_con;
514513
Mutex m_clients_mutex;
515514
// Connected clients (behind the con mutex)
516-
std::map<u16, RemoteClient*> m_clients;
515+
UNORDERED_MAP<u16, RemoteClient*> m_clients;
517516
std::vector<std::string> m_clients_names; //for announcing masterserver
518517

519518
// Environment

Diff for: ‎src/content_cao.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1505,10 +1505,8 @@ void GenericCAO::updateBonePosition()
15051505
return;
15061506

15071507
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
1508-
for(std::map<std::string,
1509-
core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin();
1510-
ii != m_bone_position.end(); ++ii)
1511-
{
1508+
for(UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
1509+
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
15121510
std::string bone_name = (*ii).first;
15131511
v3f bone_pos = (*ii).second.X;
15141512
v3f bone_rot = (*ii).second.Y;

Diff for: ‎src/content_cao.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class GenericCAO : public ClientActiveObject
9090
int m_animation_speed;
9191
int m_animation_blend;
9292
bool m_animation_loop;
93-
std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
93+
UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
9494
std::string m_attachment_bone;
9595
v3f m_attachment_position;
9696
v3f m_attachment_rotation;

Diff for: ‎src/emerge.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,10 @@ bool EmergeManager::pushBlockEmergeData(
369369
}
370370

371371

372-
bool EmergeManager::popBlockEmergeData(
373-
v3s16 pos,
374-
BlockEmergeData *bedata)
372+
bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata)
375373
{
376374
std::map<v3s16, BlockEmergeData>::iterator it;
377-
std::map<u16, u16>::iterator it2;
375+
UNORDERED_MAP<u16, u16>::iterator it2;
378376

379377
it = m_blocks_enqueued.find(pos);
380378
if (it == m_blocks_enqueued.end())

Diff for: ‎src/emerge.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class EmergeManager {
156156

157157
Mutex m_queue_mutex;
158158
std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
159-
std::map<u16, u16> m_peer_queue_count;
159+
UNORDERED_MAP<u16, u16> m_peer_queue_count;
160160

161161
u16 m_qlimit_total;
162162
u16 m_qlimit_diskonly;

0 commit comments

Comments
 (0)