diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2016-10-08 16:42:09 +0200 |
---|---|---|
committer | Ner'zhul <nerzhul@users.noreply.github.com> | 2016-10-08 22:27:44 +0200 |
commit | edba6e50d9c9c0a7120c251bed36a87b51f4c826 (patch) | |
tree | 63073d59bccd278f8b3cbbc92b6aadb1ba2e3c14 /src | |
parent | fd5a130b86c08f0b3190c3d81affd4869c139fb7 (diff) | |
download | minetest-edba6e50d9c9c0a7120c251bed36a87b51f4c826.tar.gz minetest-edba6e50d9c9c0a7120c251bed36a87b51f4c826.tar.bz2 minetest-edba6e50d9c9c0a7120c251bed36a87b51f4c826.zip |
Optimize ClientIface::getPlayerNames(): return const ref instead a copy of all names
Diffstat (limited to 'src')
-rw-r--r-- | src/clientiface.cpp | 6 | ||||
-rw-r--r-- | src/clientiface.h | 2 | ||||
-rw-r--r-- | src/server.cpp | 6 |
3 files changed, 4 insertions, 10 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index e55c07cb6..fbfc16770 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -627,12 +627,6 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state) return reply; } -std::vector<std::string> ClientInterface::getPlayerNames() -{ - return m_clients_names; -} - - void ClientInterface::step(float dtime) { m_print_info_timer += dtime; diff --git a/src/clientiface.h b/src/clientiface.h index 8985ef71f..551d71bbe 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -453,7 +453,7 @@ public: std::vector<u16> getClientIDs(ClientState min_state=CS_Active); /* get list of client player names */ - std::vector<std::string> getPlayerNames(); + const std::vector<std::string> &getPlayerNames() const { return m_clients_names; } /* send message to client */ void send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable); diff --git a/src/server.cpp b/src/server.cpp index 67dbe1545..edd97e225 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1123,11 +1123,11 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id) Print out action */ { - std::vector<std::string> names = m_clients.getPlayerNames(); + const std::vector<std::string> &names = m_clients.getPlayerNames(); - actionstream<<player->getName() <<" joins game. List of players: "; + actionstream << player->getName() << " joins game. List of players: "; - for (std::vector<std::string>::iterator i = names.begin(); + for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) { actionstream << *i << " "; } |