From e461412fdeeea5f8a75d8a0aae04186f15123757 Mon Sep 17 00:00:00 2001 From: Amos Date: Wed, 8 Jun 2022 14:35:44 +0200 Subject: [PATCH] Optimizations --- r5dev/tier1/NetAdr2.cpp | 18 +++++++++--------- r5dev/tier1/NetAdr2.h | 6 +++--- r5dev/tier1/bitbuf.cpp | 6 +++--- r5dev/tier1/bitbuf.h | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/r5dev/tier1/NetAdr2.cpp b/r5dev/tier1/NetAdr2.cpp index 00a6618b..e9d6503f 100644 --- a/r5dev/tier1/NetAdr2.cpp +++ b/r5dev/tier1/NetAdr2.cpp @@ -14,17 +14,17 @@ // Purpose: constructor (use this when string contains <[IP]:PORT>). // Input : svInAdr - //----------------------------------------------------------------------------- -CNetAdr2::CNetAdr2(string svInAdr) +CNetAdr2::CNetAdr2(const string& svInAdr) { SetIPAndPort(svInAdr); } //----------------------------------------------------------------------------- // Purpose: constructor (expects string format ). -// Input : svInAdr - -// svInPort - +// Input : &svInAdr - +// &svInPort - //----------------------------------------------------------------------------- -CNetAdr2::CNetAdr2(string svInAdr, string svInPort) +CNetAdr2::CNetAdr2(const string& svInAdr, const string& svInPort) { SetIPAndPort(svInAdr, svInPort); } @@ -43,7 +43,7 @@ CNetAdr2::~CNetAdr2(void) //----------------------------------------------------------------------------- void CNetAdr2::SetIP(const string& svInAdr) { - m_svip = "[" + svInAdr + "]"; + m_svip = '[' + svInAdr + ']'; } //----------------------------------------------------------------------------- @@ -52,7 +52,7 @@ void CNetAdr2::SetIP(const string& svInAdr) //----------------------------------------------------------------------------- void CNetAdr2::SetPort(const string& svInPort) { - m_svip += ":" + svInPort; + m_svip += ':' + svInPort; } //----------------------------------------------------------------------------- @@ -217,7 +217,7 @@ string CNetAdr2::GetBase(void) const // Purpose: removes brackets and port from IP address. // Input : svInAdr - //----------------------------------------------------------------------------- -string CNetAdr2::GetBase(string svInAdr) const +string CNetAdr2::GetBase(const string& svInAdr) const { static std::regex rx("[^\\[]*.(.*)(\\]).*"); std::smatch smRegexMatches; @@ -337,12 +337,12 @@ vector CNetAdr2::GetParts(void) const // 000.000.000.000 -> vparts. if (m_version == netadrversion_t::NA_V4) { - svDelim = "."; + svDelim = '.'; } // 0000:0000:0000:0000:0000:0000:0000:0000 -> vparts. else if (m_version == netadrversion_t::NA_V6) { - svDelim = ":"; + svDelim = ':'; StringReplace(svIpAdr, "::", ":"); } diff --git a/r5dev/tier1/NetAdr2.h b/r5dev/tier1/NetAdr2.h index 390c18c3..94bffa5c 100644 --- a/r5dev/tier1/NetAdr2.h +++ b/r5dev/tier1/NetAdr2.h @@ -19,8 +19,8 @@ class CNetAdr2 { public: CNetAdr2(void) {}; - CNetAdr2(string svInAdr); - CNetAdr2(string svInAdr, string svInPort); + CNetAdr2(const string& svInAdr); + CNetAdr2(const string& svInAdr, const string& svInPort); ~CNetAdr2(void); void SetIP(const string& svInAdr); @@ -39,7 +39,7 @@ public: netadrtype_t GetType(void) const; netadrversion_t GetVersion(void) const; string GetBase(void) const; - string GetBase(string svInAdr) const; + string GetBase(const string& svInAdr) const; vector GetParts(void) const; int GetSize(void) const; int GetFamily(void) const; diff --git a/r5dev/tier1/bitbuf.cpp b/r5dev/tier1/bitbuf.cpp index d4c0fd8c..f4ae292d 100644 --- a/r5dev/tier1/bitbuf.cpp +++ b/r5dev/tier1/bitbuf.cpp @@ -299,14 +299,14 @@ int bf_write::GetNumBytesLeft() const return this->GetNumBitsLeft() >> 3; } -unsigned char* bf_write::GetData() +unsigned char* bf_write::GetData() const { return this->m_pData; } -const unsigned char* bf_write::GetData() const +const char* bf_write::GetDebugName() const { - return this->m_pData; + return this->m_pDebugName; } bool bf_write::CheckForOverflow(int nBits) diff --git a/r5dev/tier1/bitbuf.h b/r5dev/tier1/bitbuf.h index 766a8873..97291296 100644 --- a/r5dev/tier1/bitbuf.h +++ b/r5dev/tier1/bitbuf.h @@ -73,8 +73,8 @@ public: int GetMaxNumBits() const; int GetNumBitsLeft() const; int GetNumBytesLeft() const; - unsigned char* GetData(); - const unsigned char* GetData() const; + unsigned char* GetData() const; + const char* GetDebugName() const; // Has the buffer overflowed? bool CheckForOverflow(int nBits);