From c6c08832e7ba32b56da21f40100d8ce8ed5e84a8 Mon Sep 17 00:00:00 2001 From: William Katz Date: Thu, 3 Jun 2021 18:17:43 -0700 Subject: [PATCH] reverted doggos changes till fixed --- include/log.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/include/log.hpp b/include/log.hpp index af2d55a..21c862a 100644 --- a/include/log.hpp +++ b/include/log.hpp @@ -7,25 +7,36 @@ struct Log { std::vector data; - void AddTrans(Transaction &&t) + void AddTrans(Transaction &&v) { - if (data.size() == max_log_size) // If we hit the max size + if (data.capacity() == data.size() && data.size() < max_log_size) //if memory reserved is full and max isnt reached { - for (auto i = data.size() - 1; i > 0; i--) // Make room at the back + if (data.size() + pre_log_size > max_log_size) //if prefetched memory is larger then max { - data[i - 1] == std::move(data[i]) // Shifts everything left + data.reserve(max_log_size); //just allocate max + } + else + { + data.reserve(data.size() + pre_log_size); //prefetching memory } } - else if (data.size() == data.capacity()) // If we haven't hit the max but hit capacity + if (data.size() == max_log_size) { - data.reserve(data.capacity() + pre_alloc) // Reserve more memory + for (size_t i = 0; i < data.size() - 1; ++i) + { + data[i] = std::move(data[i + 1]); + } + data[data.size() - 1] = std::move(v); + } + else + { + data.push_back(std::move(v)); } - data[data.size() - 1] = std::move(t) // In any case, place new at the back } Json::Value Serialize() const { Json::Value res; - for (uint32_t i = 0; i < end; ++i) + for (uint32_t i = 0; i < data.size(); ++i) { res[i]["to"] = data[i].to; res[i]["from"] = data[i].from;