Merge pull request #8576 from def-/pr-mem-copy

Make FillAntibot faster
This commit is contained in:
heinrich5991 2024-07-10 13:24:15 +00:00 committed by GitHub
commit 89992f2ce5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -270,7 +270,7 @@ public:
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;
@ -420,7 +420,7 @@ public:
// 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; }