Optimization and cleanup

This commit is contained in:
Adam Ierymenko 2019-08-26 20:18:28 -07:00
parent 8203547cfc
commit 6f22570648
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
17 changed files with 261 additions and 266 deletions

View file

@ -35,36 +35,36 @@ public:
typedef char * iterator;
typedef const char * const_iterator;
inline Str() { _l = 0; _s[0] = 0; }
inline Str(const Str &s)
ZT_ALWAYS_INLINE Str() { _l = 0; _s[0] = 0; }
ZT_ALWAYS_INLINE Str(const Str &s)
{
_l = s._l;
memcpy(_s,s._s,_l+1);
}
inline Str(const char *s)
ZT_ALWAYS_INLINE Str(const char *s)
{
_l = 0;
_s[0] = 0;
(*this) << s;
}
inline Str(const std::string &s)
ZT_ALWAYS_INLINE Str(const std::string &s)
{
*this = s;
}
inline Str &operator=(const Str &s)
ZT_ALWAYS_INLINE Str &operator=(const Str &s)
{
_l = s._l;
memcpy(_s,s._s,_l+1);
return *this;
}
inline Str &operator=(const char *s)
ZT_ALWAYS_INLINE Str &operator=(const char *s)
{
_l = 0;
_s[0] = 0;
return ((*this) << s);
}
inline Str &operator=(const std::string &s)
ZT_ALWAYS_INLINE Str &operator=(const std::string &s)
{
if (s.length() > ZT_STR_CAPACITY) {
_l = 0;
@ -78,23 +78,23 @@ public:
return *this;
}
inline char operator[](const unsigned int i) const
ZT_ALWAYS_INLINE char operator[](const unsigned int i) const
{
if (unlikely(i >= (unsigned int)_l))
throw ZT_EXCEPTION_OUT_OF_BOUNDS;
return _s[i];
}
inline void clear() { _l = 0; _s[0] = 0; }
inline const char *c_str() const { return _s; }
inline unsigned int length() const { return (unsigned int)_l; }
inline bool empty() const { return (_l == 0); }
inline iterator begin() { return (iterator)_s; }
inline iterator end() { return (iterator)(_s + (unsigned long)_l); }
inline const_iterator begin() const { return (const_iterator)_s; }
inline const_iterator end() const { return (const_iterator)(_s + (unsigned long)_l); }
ZT_ALWAYS_INLINE void clear() { _l = 0; _s[0] = 0; }
ZT_ALWAYS_INLINE const char *c_str() const { return _s; }
ZT_ALWAYS_INLINE unsigned int length() const { return (unsigned int)_l; }
ZT_ALWAYS_INLINE bool empty() const { return (_l == 0); }
ZT_ALWAYS_INLINE iterator begin() { return (iterator)_s; }
ZT_ALWAYS_INLINE iterator end() { return (iterator)(_s + (unsigned long)_l); }
ZT_ALWAYS_INLINE const_iterator begin() const { return (const_iterator)_s; }
ZT_ALWAYS_INLINE const_iterator end() const { return (const_iterator)(_s + (unsigned long)_l); }
inline Str &operator<<(const char *s)
ZT_ALWAYS_INLINE Str &operator<<(const char *s)
{
if (likely(s != (const char *)0)) {
unsigned long l = _l;
@ -112,8 +112,8 @@ public:
}
return *this;
}
inline Str &operator<<(const Str &s) { return ((*this) << s._s); }
inline Str &operator<<(const char c)
ZT_ALWAYS_INLINE Str &operator<<(const Str &s) { return ((*this) << s._s); }
ZT_ALWAYS_INLINE Str &operator<<(const char c)
{
if (unlikely(_l >= ZT_STR_CAPACITY)) {
_s[ZT_STR_CAPACITY] = 0;
@ -123,49 +123,49 @@ public:
_s[(unsigned long)_l] = 0;
return *this;
}
inline Str &operator<<(const unsigned long n)
ZT_ALWAYS_INLINE Str &operator<<(const unsigned long n)
{
char tmp[32];
Utils::decimal(n,tmp);
return ((*this) << tmp);
}
inline Str &operator<<(const unsigned int n)
ZT_ALWAYS_INLINE Str &operator<<(const unsigned int n)
{
char tmp[32];
Utils::decimal((unsigned long)n,tmp);
return ((*this) << tmp);
}
inline Str &operator<<(const Address &a)
ZT_ALWAYS_INLINE Str &operator<<(const Address &a)
{
char tmp[32];
return ((*this) << a.toString(tmp));
}
inline Str &operator<<(const InetAddress &a)
ZT_ALWAYS_INLINE Str &operator<<(const InetAddress &a)
{
char tmp[128];
return ((*this) << a.toString(tmp));
}
inline Str &operator<<(const MAC &a)
ZT_ALWAYS_INLINE Str &operator<<(const MAC &a)
{
char tmp[64];
return ((*this) << a.toString(tmp));
}
inline operator bool() const { return (_l != 0); }
ZT_ALWAYS_INLINE operator bool() const { return (_l != 0); }
inline bool operator==(const Str &s) const { return ((_l == s._l)&&(strcmp(_s,s._s) == 0)); }
inline bool operator!=(const Str &s) const { return ((_l != s._l)||(strcmp(_s,s._s) != 0)); }
inline bool operator<(const Str &s) const { return ((_l < s._l)&&(strcmp(_s,s._s) < 0)); }
inline bool operator>(const Str &s) const { return ((_l > s._l)&&(strcmp(_s,s._s) > 0)); }
inline bool operator<=(const Str &s) const { return ((_l <= s._l)&&(strcmp(_s,s._s) <= 0)); }
inline bool operator>=(const Str &s) const { return ((_l >= s._l)&&(strcmp(_s,s._s) >= 0)); }
ZT_ALWAYS_INLINE bool operator==(const Str &s) const { return ((_l == s._l)&&(strcmp(_s,s._s) == 0)); }
ZT_ALWAYS_INLINE bool operator!=(const Str &s) const { return ((_l != s._l)||(strcmp(_s,s._s) != 0)); }
ZT_ALWAYS_INLINE bool operator<(const Str &s) const { return ((_l < s._l)&&(strcmp(_s,s._s) < 0)); }
ZT_ALWAYS_INLINE bool operator>(const Str &s) const { return ((_l > s._l)&&(strcmp(_s,s._s) > 0)); }
ZT_ALWAYS_INLINE bool operator<=(const Str &s) const { return ((_l <= s._l)&&(strcmp(_s,s._s) <= 0)); }
ZT_ALWAYS_INLINE bool operator>=(const Str &s) const { return ((_l >= s._l)&&(strcmp(_s,s._s) >= 0)); }
inline bool operator==(const char *s) const { return (strcmp(_s,s) == 0); }
inline bool operator!=(const char *s) const { return (strcmp(_s,s) != 0); }
inline bool operator<(const char *s) const { return (strcmp(_s,s) < 0); }
inline bool operator>(const char *s) const { return (strcmp(_s,s) > 0); }
inline bool operator<=(const char *s) const { return (strcmp(_s,s) <= 0); }
inline bool operator>=(const char *s) const { return (strcmp(_s,s) >= 0); }
ZT_ALWAYS_INLINE bool operator==(const char *s) const { return (strcmp(_s,s) == 0); }
ZT_ALWAYS_INLINE bool operator!=(const char *s) const { return (strcmp(_s,s) != 0); }
ZT_ALWAYS_INLINE bool operator<(const char *s) const { return (strcmp(_s,s) < 0); }
ZT_ALWAYS_INLINE bool operator>(const char *s) const { return (strcmp(_s,s) > 0); }
ZT_ALWAYS_INLINE bool operator<=(const char *s) const { return (strcmp(_s,s) <= 0); }
ZT_ALWAYS_INLINE bool operator>=(const char *s) const { return (strcmp(_s,s) >= 0); }
private:
uint8_t _l;