Optimize ClientIface::getPlayerNames(): return const ref instead a copy of all names
authorLoic Blot <loic.blot@unix-experience.fr>
Sat, 8 Oct 2016 14:42:09 +0000 (16:42 +0200)
committerNer'zhul <nerzhul@users.noreply.github.com>
Sat, 8 Oct 2016 20:27:44 +0000 (22:27 +0200)
src/clientiface.cpp
src/clientiface.h
src/server.cpp

index e55c07cb628cece04b1e5a34069b628f8f124bbd..fbfc16770118c0fe452add5232b3078b23d6afb4 100644 (file)
@@ -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;
index 8985ef71feb9bb98487992f7354cb9ddf9290c88..551d71bbe48ec76fad6acefc85c166f05b0b1c13 100644 (file)
@@ -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);
index 67dbe154518b9869dee35e53dde1e3220c871f7d..edd97e2258204eadbbaf0402210bc5e8b28c288d 100644 (file)
@@ -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 << " ";
                }