From e1124683953c80aff458bd900f2410be616b7840 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 13 Jul 2021 20:25:41 -0700 Subject: [PATCH] :racehorse: changed log structure from vector to deque --- include/log.h | 7 +++---- src/log.cpp | 11 +++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/include/log.h b/include/log.h index 8988048..27d9cc0 100644 --- a/include/log.h +++ b/include/log.h @@ -1,7 +1,6 @@ #pragma once #include // to be removed later -#include -#include +#include #include "ccash_config.hpp" #include "change_flag.h" #include "transaction.h" @@ -19,10 +18,10 @@ public: #if MAX_LOG_SIZE == 1 Transaction data; #else - std::vector data; + std::deque data; #endif std::string GetLogs() noexcept; - void AddTrans(const Transaction &t) noexcept; + void AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept; Json::Value Serialize() const; // to be removed later }; diff --git a/src/log.cpp b/src/log.cpp index cdaeb6b..06185cc 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,6 +1,6 @@ #include "log.h" -void Log::AddTrans(const Transaction &t) noexcept +void Log::AddTrans(const std::string &from, const std::string &to, uint32_t amount, time_t time) noexcept { log_flag.SetChangesOn(); #if MAX_LOG_SIZE == 1 @@ -8,14 +8,9 @@ void Log::AddTrans(const Transaction &t) noexcept #else if (data.size() == MAX_LOG_SIZE) // If we hit the max size { - for (size_t i = 1; i < data.size(); i++) // Make room at the back - { - data[i - 1] = std::move(data[i]); // Shifts everything left - } - data[data.size() - 1] = std::move(t); // Place new in opened spot - return; + data.pop_back(); } - data.push_back(t); // In either case we have space under max length, move to new spot + data.emplace_back(from, to, amount, time); // In either case we have space under max length, move to new spot #endif }