more opt
This commit is contained in:
parent
b727e2a67a
commit
f12370c348
4 changed files with 82 additions and 82 deletions
|
@ -33,24 +33,24 @@ namespace ZeroTier {
|
|||
class Address
|
||||
{
|
||||
public:
|
||||
inline Address() : _a(0) {}
|
||||
inline Address(const Address &a) : _a(a._a) {}
|
||||
inline Address(uint64_t a) : _a(a & 0xffffffffffULL) {}
|
||||
ZT_ALWAYS_INLINE Address() : _a(0) {}
|
||||
ZT_ALWAYS_INLINE Address(const Address &a) : _a(a._a) {}
|
||||
ZT_ALWAYS_INLINE Address(uint64_t a) : _a(a & 0xffffffffffULL) {}
|
||||
|
||||
/**
|
||||
* @param bits Raw address -- 5 bytes, big-endian byte order
|
||||
* @param len Length of array
|
||||
*/
|
||||
inline Address(const void *bits,unsigned int len) { setTo(bits,len); }
|
||||
ZT_ALWAYS_INLINE Address(const void *bits,unsigned int len) { setTo(bits,len); }
|
||||
|
||||
inline Address &operator=(const Address &a) { _a = a._a; return *this; }
|
||||
inline Address &operator=(const uint64_t a) { _a = (a & 0xffffffffffULL); return *this; }
|
||||
ZT_ALWAYS_INLINE Address &operator=(const Address &a) { _a = a._a; return *this; }
|
||||
ZT_ALWAYS_INLINE Address &operator=(const uint64_t a) { _a = (a & 0xffffffffffULL); return *this; }
|
||||
|
||||
/**
|
||||
* @param bits Raw address -- 5 bytes, big-endian byte order
|
||||
* @param len Length of array
|
||||
*/
|
||||
inline void setTo(const void *bits,const unsigned int len)
|
||||
ZT_ALWAYS_INLINE void setTo(const void *bits,const unsigned int len)
|
||||
{
|
||||
if (len < ZT_ADDRESS_LENGTH) {
|
||||
_a = 0;
|
||||
|
@ -69,7 +69,7 @@ public:
|
|||
* @param bits Buffer to hold 5-byte address in big-endian byte order
|
||||
* @param len Length of array
|
||||
*/
|
||||
inline void copyTo(void *const bits,const unsigned int len) const
|
||||
ZT_ALWAYS_INLINE void copyTo(void *const bits,const unsigned int len) const
|
||||
{
|
||||
if (len < ZT_ADDRESS_LENGTH)
|
||||
return;
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
* @param b Buffer to append to
|
||||
*/
|
||||
template<unsigned int C>
|
||||
inline void appendTo(Buffer<C> &b) const
|
||||
ZT_ALWAYS_INLINE void appendTo(Buffer<C> &b) const
|
||||
{
|
||||
unsigned char *p = (unsigned char *)b.appendField(ZT_ADDRESS_LENGTH);
|
||||
*(p++) = (unsigned char)((_a >> 32) & 0xff);
|
||||
|
@ -100,22 +100,22 @@ public:
|
|||
/**
|
||||
* @return Integer containing address (0 to 2^40)
|
||||
*/
|
||||
inline uint64_t toInt() const { return _a; }
|
||||
ZT_ALWAYS_INLINE uint64_t toInt() const { return _a; }
|
||||
|
||||
/**
|
||||
* @return Hash code for use with Hashtable
|
||||
*/
|
||||
inline unsigned long hashCode() const { return (unsigned long)_a; }
|
||||
ZT_ALWAYS_INLINE unsigned long hashCode() const { return (unsigned long)_a; }
|
||||
|
||||
/**
|
||||
* @return Hexadecimal string
|
||||
*/
|
||||
inline char *toString(char buf[11]) const { return Utils::hex10(_a,buf); }
|
||||
ZT_ALWAYS_INLINE char *toString(char buf[11]) const { return Utils::hex10(_a,buf); }
|
||||
|
||||
/**
|
||||
* @return True if this address is not zero
|
||||
*/
|
||||
inline operator bool() const { return (_a != 0); }
|
||||
ZT_ALWAYS_INLINE operator bool() const { return (_a != 0); }
|
||||
|
||||
/**
|
||||
* Check if this address is reserved
|
||||
|
@ -126,29 +126,29 @@ public:
|
|||
*
|
||||
* @return True if address is reserved and may not be used
|
||||
*/
|
||||
inline bool isReserved() const { return ((!_a)||((_a >> 32) == ZT_ADDRESS_RESERVED_PREFIX)); }
|
||||
ZT_ALWAYS_INLINE bool isReserved() const { return ((!_a)||((_a >> 32) == ZT_ADDRESS_RESERVED_PREFIX)); }
|
||||
|
||||
/**
|
||||
* @param i Value from 0 to 4 (inclusive)
|
||||
* @return Byte at said position (address interpreted in big-endian order)
|
||||
*/
|
||||
inline uint8_t operator[](unsigned int i) const { return (uint8_t)(_a >> (32 - (i * 8))); }
|
||||
ZT_ALWAYS_INLINE uint8_t operator[](unsigned int i) const { return (uint8_t)(_a >> (32 - (i * 8))); }
|
||||
|
||||
inline void zero() { _a = 0; }
|
||||
ZT_ALWAYS_INLINE void zero() { _a = 0; }
|
||||
|
||||
inline bool operator==(const uint64_t &a) const { return (_a == (a & 0xffffffffffULL)); }
|
||||
inline bool operator!=(const uint64_t &a) const { return (_a != (a & 0xffffffffffULL)); }
|
||||
inline bool operator>(const uint64_t &a) const { return (_a > (a & 0xffffffffffULL)); }
|
||||
inline bool operator<(const uint64_t &a) const { return (_a < (a & 0xffffffffffULL)); }
|
||||
inline bool operator>=(const uint64_t &a) const { return (_a >= (a & 0xffffffffffULL)); }
|
||||
inline bool operator<=(const uint64_t &a) const { return (_a <= (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator==(const uint64_t &a) const { return (_a == (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const uint64_t &a) const { return (_a != (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator>(const uint64_t &a) const { return (_a > (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator<(const uint64_t &a) const { return (_a < (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator>=(const uint64_t &a) const { return (_a >= (a & 0xffffffffffULL)); }
|
||||
ZT_ALWAYS_INLINE bool operator<=(const uint64_t &a) const { return (_a <= (a & 0xffffffffffULL)); }
|
||||
|
||||
inline bool operator==(const Address &a) const { return (_a == a._a); }
|
||||
inline bool operator!=(const Address &a) const { return (_a != a._a); }
|
||||
inline bool operator>(const Address &a) const { return (_a > a._a); }
|
||||
inline bool operator<(const Address &a) const { return (_a < a._a); }
|
||||
inline bool operator>=(const Address &a) const { return (_a >= a._a); }
|
||||
inline bool operator<=(const Address &a) const { return (_a <= a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator==(const Address &a) const { return (_a == a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const Address &a) const { return (_a != a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator>(const Address &a) const { return (_a > a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator<(const Address &a) const { return (_a < a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator>=(const Address &a) const { return (_a >= a._a); }
|
||||
ZT_ALWAYS_INLINE bool operator<=(const Address &a) const { return (_a <= a._a); }
|
||||
|
||||
private:
|
||||
uint64_t _a;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue