Skip to content

Commit

Permalink
Merge pull request ddnet#8576 from def-/pr-mem-copy
Browse files Browse the repository at this point in the history
Make FillAntibot faster
  • Loading branch information
heinrich5991 authored Jul 10, 2024
2 parents fa9f7b4 + 108d0dc commit 89992f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,11 @@ void CServer::FillAntibot(CAntibotRoundData *pData)
for(int i = 0; i < MAX_CLIENTS; i++)
{
CAntibotPlayerData *pPlayer = &pData->m_aPlayers[i];
str_copy(pPlayer->m_aAddress, m_NetServer.ClientAddrString(i));
// No need for expensive str_copy since we don't truncate and the string is
// ASCII anyway
static_assert(std::size((CAntibotPlayerData{}).m_aAddress) >= NETADDR_MAXSTRSIZE);
static_assert(sizeof(*(CNetServer{}).ClientAddrString(i)) == NETADDR_MAXSTRSIZE);
mem_copy(pPlayer->m_aAddress, m_NetServer.ClientAddrString(i), NETADDR_MAXSTRSIZE);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/shared/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CNetConnection
void SignalResend();
int State() const { return m_State; }
const NETADDR *PeerAddress() const { return &m_PeerAddr; }
const char *PeerAddressString() const { return m_aPeerAddrStr; }
const char (*PeerAddressString() const)[NETADDR_MAXSTRSIZE] { return &m_aPeerAddrStr; }
void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const
{
*ppAddrs = m_aConnectAddrs;
Expand Down Expand Up @@ -420,7 +420,7 @@ class CNetServer

// status requests
const NETADDR *ClientAddr(int ClientId) const { return m_aSlots[ClientId].m_Connection.PeerAddress(); }
const char *ClientAddrString(int ClientID) const { return m_aSlots[ClientID].m_Connection.PeerAddressString(); }
const char (*ClientAddrString(int ClientID) const)[NETADDR_MAXSTRSIZE] { return m_aSlots[ClientID].m_Connection.PeerAddressString(); }
bool HasSecurityToken(int ClientId) const { return m_aSlots[ClientId].m_Connection.SecurityToken() != NET_SECURITY_TOKEN_UNSUPPORTED; }
NETADDR Address() const { return m_Address; }
NETSOCKET Socket() const { return m_Socket; }
Expand Down

0 comments on commit 89992f2

Please sign in to comment.