Skip to content
/ bro Public
forked from zeek/zeek

Commit

Permalink
Internal UID simplifications/nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiwek committed Sep 4, 2013
1 parent ca9b916 commit 0678468
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
8 changes: 0 additions & 8 deletions src/UID.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ void UID::Set(bro_uint_t bits, const uint64* v, size_t n)
if ( 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;
}
15 changes: 5 additions & 10 deletions src/UID.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class UID {
/**
* 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.
Expand All @@ -85,21 +86,15 @@ class 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)
{
for ( size_t i = 0; i < BRO_UID_LEN; ++i )
uid[i] = other.uid[i];

memcpy(uid, other.uid, sizeof(uid));
initialized = other.initialized;
}

inline UID& UID::operator=(const UID& other)
{
for ( size_t i = 0; i < BRO_UID_LEN; ++i )
uid[i] = other.uid[i];

memmove(uid, other.uid, sizeof(uid));
initialized = other.initialized;
return *this;
}
Expand All @@ -109,7 +104,7 @@ inline std::string UID::Base62(std::string prefix) const
if ( ! initialized )
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 )
prefix.append(uitoa_n(uid[i], tmp, sizeof(tmp), 62));

Expand Down

0 comments on commit 0678468

Please sign in to comment.