From 8e1019a265644c1adb35bd9d74002f47cee98519 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 5 Jun 2023 01:45:33 +0200 Subject: [PATCH] Make simple CNetAdr methods inline Should be inline for their simplicity to improve performance. --- r5dev/public/tier1/NetAdr.h | 29 ++++++++------- r5dev/tier1/NetAdr.cpp | 72 ------------------------------------- 2 files changed, 14 insertions(+), 87 deletions(-) diff --git a/r5dev/public/tier1/NetAdr.h b/r5dev/public/tier1/NetAdr.h index 71e14b94..1d70dbad 100644 --- a/r5dev/public/tier1/NetAdr.h +++ b/r5dev/public/tier1/NetAdr.h @@ -15,29 +15,28 @@ enum class netadrtype_t class CNetAdr { public: - CNetAdr(void); - CNetAdr(const char* pch); + CNetAdr(void) { Clear(); } + CNetAdr(const char* pch) { SetFromString(pch); } void Clear(void); - void SetIP(IN6_ADDR* inAdr); - void SetPort(uint16_t port); - void SetType(netadrtype_t type); + inline void SetIP(IN6_ADDR* inAdr) { adr = *inAdr; } + inline void SetPort(uint16_t newport) { port = newport; } + inline void SetType(netadrtype_t newtype) { type = newtype; } bool SetFromSockadr(struct sockaddr_storage* s); bool SetFromString(const char* pch, bool bUseDNS = false); - netadrtype_t GetType(void) const; - uint16_t GetPort(void) const; + inline netadrtype_t GetType(void) const { return type; } + inline uint16_t GetPort(void) const { return port; } - bool CompareAdr(const CNetAdr& other) const; - bool ComparePort(const CNetAdr& other) const; + bool CompareAdr(const CNetAdr& other) const; + inline bool ComparePort(const CNetAdr& other) const { return port == other.port; } + inline bool IsLoopback(void) const { return type == netadrtype_t::NA_LOOPBACK; } // true if engine loopback buffers are used. - const char* ToString(bool onlyBase = false) const; - void ToString(char* pchBuffer, size_t unBufferSize, bool onlyBase = false) const; - void ToAdrinfo(addrinfo* pHint) const; - - void ToSockadr(struct sockaddr_storage* s) const; - bool IsLoopback(void) const; // true if engine loopback buffers are used. + const char* ToString(bool onlyBase = false) const; + void ToString(char* pchBuffer, size_t unBufferSize, bool onlyBase = false) const; + void ToAdrinfo(addrinfo* pHint) const; + void ToSockadr(struct sockaddr_storage* s) const; private: netadrtype_t type; diff --git a/r5dev/tier1/NetAdr.cpp b/r5dev/tier1/NetAdr.cpp index 9618695f..12cb6d39 100644 --- a/r5dev/tier1/NetAdr.cpp +++ b/r5dev/tier1/NetAdr.cpp @@ -7,22 +7,6 @@ #include "tier1/NetAdr.h" #include "tier1/strtools.h" -////////////////////////////////////////////////////////////////////// -// Constructors. -////////////////////////////////////////////////////////////////////// -CNetAdr::CNetAdr(void) -{ - Clear(); -} - -////////////////////////////////////////////////////////////////////// -// Constructors. -////////////////////////////////////////////////////////////////////// -CNetAdr::CNetAdr(const char* pch) -{ - SetFromString(pch); -} - ////////////////////////////////////////////////////////////////////// // Clears IP. ////////////////////////////////////////////////////////////////////// @@ -34,46 +18,6 @@ void CNetAdr::Clear(void) type = netadrtype_t::NA_NULL; } -////////////////////////////////////////////////////////////////////// -// Sets IP. -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetIP(IN6_ADDR* inAdr) -{ - adr = *inAdr; -} - -////////////////////////////////////////////////////////////////////// -// Sets the address type. -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetType(netadrtype_t newtype) -{ - type = newtype; -} - -////////////////////////////////////////////////////////////////////// -// Returns the address type. -////////////////////////////////////////////////////////////////////// -netadrtype_t CNetAdr::GetType(void) const -{ - return type; -} - -////////////////////////////////////////////////////////////////////// -// Sets the port (must be network byte order, use 'htons' to flip). -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetPort(uint16_t newport) -{ - port = newport; -} - -////////////////////////////////////////////////////////////////////// -// Returns the port in network byte order (use 'ntohs' to flip). -////////////////////////////////////////////////////////////////////// -uint16_t CNetAdr::GetPort(void) const -{ - return port; -} - ////////////////////////////////////////////////////////////////////// // Compares two addresses. ////////////////////////////////////////////////////////////////////// @@ -95,14 +39,6 @@ bool CNetAdr::CompareAdr(const CNetAdr& other) const return false; } -////////////////////////////////////////////////////////////////////// -// Compares two ports. -////////////////////////////////////////////////////////////////////// -bool CNetAdr::ComparePort(const CNetAdr& other) const -{ - return port == other.port; -} - ////////////////////////////////////////////////////////////////////// // Convert address to string. ////////////////////////////////////////////////////////////////////// @@ -217,14 +153,6 @@ bool CNetAdr::SetFromSockadr(struct sockaddr_storage* s) return true; } -////////////////////////////////////////////////////////////////////// -// Returns true if we use the loopback buffers. -////////////////////////////////////////////////////////////////////// -bool CNetAdr::IsLoopback(void) const -{ - return type == netadrtype_t::NA_LOOPBACK; -} - ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////