Code comments for logs

This commit is contained in:
doggo 2021-06-03 16:50:13 -05:00
parent a2287a4d36
commit af51335aa7

View file

@ -9,17 +9,18 @@ struct Log
std::vector<Transaction> data; std::vector<Transaction> data;
void AddTrans(Transaction &&t) void AddTrans(Transaction &&t)
{ {
if (data.size() == max_log_size) if (data.size() == max_log_size) // If we hit the max size
{ {
for (auto i = data.size() - 1; i > 0; i--) for (auto i = data.size() - 1; i > 0; i--) // Make room at the back
{ {
data[i - 1] == std::move(data[i]) data[i - 1] == std::move(data[i])
} }
} }
else if (data.size() == data.capacity()) { else if (data.size() == data.capacity()) // If we haven't hit the max but hit capacity
data.reserve(data.capacity() + pre_alloc) {
data.reserve(data.capacity() + pre_alloc) // Reserve more memory
} }
data[data.size() - 1] = std::move(t) data[data.size() - 1] = std::move(t) // In any case, place new at the back
} }
Json::Value Serialize() const Json::Value Serialize() const
{ {