Reformat Zeek in Spicy style

This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
This commit is contained in:
Benjamin Bannier 2023-10-10 21:13:34 +02:00
parent 7b8e7ed72c
commit f5a76c1aed
786 changed files with 131714 additions and 153609 deletions

View file

@ -2,82 +2,73 @@
#include <cstring>
namespace zeek::session::detail
{
namespace zeek::session::detail {
Key::Key(const void* session, size_t size, size_t type, bool copy) : size(size), type(type)
{
data = reinterpret_cast<const uint8_t*>(session);
Key::Key(const void* session, size_t size, size_t type, bool copy) : size(size), type(type) {
data = reinterpret_cast<const uint8_t*>(session);
if ( copy )
CopyData();
if ( copy )
CopyData();
copied = copy;
}
copied = copy;
}
Key::Key(Key&& rhs)
{
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
Key::Key(Key&& rhs) {
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
Key& Key::operator=(Key&& rhs)
{
if ( this != &rhs )
{
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
Key& Key::operator=(Key&& rhs) {
if ( this != &rhs ) {
data = rhs.data;
size = rhs.size;
copied = rhs.copied;
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
rhs.data = nullptr;
rhs.size = 0;
rhs.copied = false;
}
return *this;
}
return *this;
}
Key::~Key()
{
if ( copied )
delete[] data;
}
Key::~Key() {
if ( copied )
delete[] data;
}
void Key::CopyData()
{
if ( copied )
return;
void Key::CopyData() {
if ( copied )
return;
copied = true;
copied = true;
uint8_t* temp = new uint8_t[size];
memcpy(temp, data, size);
data = temp;
}
uint8_t* temp = new uint8_t[size];
memcpy(temp, data, size);
data = temp;
}
bool Key::operator<(const Key& rhs) const
{
if ( size != rhs.size )
return size < rhs.size;
else if ( type != rhs.type )
return type < rhs.type;
bool Key::operator<(const Key& rhs) const {
if ( size != rhs.size )
return size < rhs.size;
else if ( type != rhs.type )
return type < rhs.type;
return memcmp(data, rhs.data, size) < 0;
}
return memcmp(data, rhs.data, size) < 0;
}
bool Key::operator==(const Key& rhs) const
{
if ( size != rhs.size )
return false;
else if ( type != rhs.type )
return false;
bool Key::operator==(const Key& rhs) const {
if ( size != rhs.size )
return false;
else if ( type != rhs.type )
return false;
return memcmp(data, rhs.data, size) == 0;
}
return memcmp(data, rhs.data, size) == 0;
}
} // namespace zeek::session::detail
} // namespace zeek::session::detail