Internal UID simplifications/nits.

This commit is contained in:
Jon Siwek 2013-09-04 11:46:53 -05:00
parent ca9b9162a7
commit 0678468353
2 changed files with 5 additions and 18 deletions

View file

@ -26,11 +26,3 @@ void UID::Set(bro_uint_t bits, const uint64* v, size_t n)
if ( res.rem ) if ( res.rem )
uid[0] >>= 64 - res.rem; uid[0] >>= 64 - res.rem;
} }
bool Bro::operator==(const UID& u1, const UID& u2)
{
for ( size_t i = 0; i < BRO_UID_LEN; ++i )
if ( u1.uid[i] != u2.uid[i] )
return false;
return true;
}

View file

@ -72,7 +72,8 @@ public:
/** /**
* UID equality operator. * UID equality operator.
*/ */
friend bool operator==(const UID& u1, const UID& u2); friend bool operator==(const UID& u1, const UID& u2)
{ return memcmp(u1.uid, u2.uid, sizeof(u1.uid)) == 0; }
/** /**
* UID inequality operator. * UID inequality operator.
@ -85,21 +86,15 @@ private:
bool initialized; // Since technically uid == 0 is a legit UID bool initialized; // Since technically uid == 0 is a legit UID
}; };
bool operator==(const UID& u1, const UID& u2);
inline UID::UID(const UID& other) inline UID::UID(const UID& other)
{ {
for ( size_t i = 0; i < BRO_UID_LEN; ++i ) memcpy(uid, other.uid, sizeof(uid));
uid[i] = other.uid[i];
initialized = other.initialized; initialized = other.initialized;
} }
inline UID& UID::operator=(const UID& other) inline UID& UID::operator=(const UID& other)
{ {
for ( size_t i = 0; i < BRO_UID_LEN; ++i ) memmove(uid, other.uid, sizeof(uid));
uid[i] = other.uid[i];
initialized = other.initialized; initialized = other.initialized;
return *this; return *this;
} }
@ -109,7 +104,7 @@ inline std::string UID::Base62(std::string prefix) const
if ( ! initialized ) if ( ! initialized )
reporter->InternalError("use of uninitialized UID"); reporter->InternalError("use of uninitialized UID");
char tmp[64]; // technically, this should dynamically scale w/ BRO_UID_LEN char tmp[sizeof(uid) * 8 + 1]; // enough for even binary representation
for ( size_t i = 0; i < BRO_UID_LEN; ++i ) for ( size_t i = 0; i < BRO_UID_LEN; ++i )
prefix.append(uitoa_n(uid[i], tmp, sizeof(tmp), 62)); prefix.append(uitoa_n(uid[i], tmp, sizeof(tmp), 62));