Skip to content

Commit 4ecfd3e

Browse files
committed
Inline short, often-called, rarely-changed basic CNetAddr getters
and make them nodiscard. Member functions containing a few lines of code are usually inlined, either implicitly by defining them in the declaration as done here, or declared inline. References https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-inline https://google.github.io/styleguide/cppguide#Inline_Functions https://www.ibm.com/docs/en/i/7.1?topic=only-inline-member-functions-c
1 parent 5316ae5 commit 4ecfd3e

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/netaddress.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ bool CNetAddr::IsBindAny() const
309309
return std::all_of(m_addr.begin(), m_addr.end(), [](uint8_t b) { return b == 0; });
310310
}
311311

312-
bool CNetAddr::IsIPv4() const { return m_net == NET_IPV4; }
313-
314-
bool CNetAddr::IsIPv6() const { return m_net == NET_IPV6; }
315-
316312
bool CNetAddr::IsRFC1918() const
317313
{
318314
return IsIPv4() && (
@@ -400,22 +396,6 @@ bool CNetAddr::IsHeNet() const
400396
return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x04, 0x70});
401397
}
402398

403-
/**
404-
* Check whether this object represents a TOR address.
405-
* @see CNetAddr::SetSpecial(const std::string &)
406-
*/
407-
bool CNetAddr::IsTor() const { return m_net == NET_ONION; }
408-
409-
/**
410-
* Check whether this object represents an I2P address.
411-
*/
412-
bool CNetAddr::IsI2P() const { return m_net == NET_I2P; }
413-
414-
/**
415-
* Check whether this object represents a CJDNS address.
416-
*/
417-
bool CNetAddr::IsCJDNS() const { return m_net == NET_CJDNS; }
418-
419399
bool CNetAddr::IsLocal() const
420400
{
421401
// IPv4 loopback (127.0.0.0/8 or 0.0.0.0/8)

src/netaddress.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class CNetAddr
162162
bool SetSpecial(const std::string& addr);
163163

164164
bool IsBindAny() const; // INADDR_ANY equivalent
165-
bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
166-
bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
165+
[[nodiscard]] bool IsIPv4() const { return m_net == NET_IPV4; } // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
166+
[[nodiscard]] bool IsIPv6() const { return m_net == NET_IPV6; } // IPv6 address (not mapped IPv4, not Tor)
167167
bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
168168
bool IsRFC2544() const; // IPv4 inter-network communications (198.18.0.0/15)
169169
bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10)
@@ -179,9 +179,9 @@ class CNetAddr
179179
bool IsRFC6052() const; // IPv6 well-known prefix for IPv4-embedded address (64:FF9B::/96)
180180
bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) (actually defined in RFC2765)
181181
bool IsHeNet() const; // IPv6 Hurricane Electric - https://he.net (2001:0470::/36)
182-
bool IsTor() const;
183-
bool IsI2P() const;
184-
bool IsCJDNS() const;
182+
[[nodiscard]] bool IsTor() const { return m_net == NET_ONION; }
183+
[[nodiscard]] bool IsI2P() const { return m_net == NET_I2P; }
184+
[[nodiscard]] bool IsCJDNS() const { return m_net == NET_CJDNS; }
185185
[[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == 0xfc; }
186186
bool IsLocal() const;
187187
bool IsRoutable() const;

0 commit comments

Comments
 (0)