Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimize ClientIface::getPlayerNames(): return const ref instead a co…
…py of all names
  • Loading branch information
nerzhul committed Oct 8, 2016
1 parent fd5a130 commit edba6e5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/clientiface.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/clientiface.h
Expand Up @@ -453,7 +453,7 @@ class ClientInterface {
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);
Expand Down
6 changes: 3 additions & 3 deletions src/server.cpp
Expand Up @@ -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 << " ";
}
Expand Down

0 comments on commit edba6e5

Please sign in to comment.