From 754f1e52f2ca1ec129151bb5c3c43fbc8a0c6c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 13 Oct 2024 16:29:12 +0000 Subject: [PATCH] Reimplementation of MySQL_Logger_CircularBuffer::get_all_events() Accept a reference to a vector instead of returning a deque --- include/MySQL_Logger.hpp | 9 +++++---- lib/MySQL_Logger.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/MySQL_Logger.hpp b/include/MySQL_Logger.hpp index 39c90044b..5c27b5b21 100644 --- a/include/MySQL_Logger.hpp +++ b/include/MySQL_Logger.hpp @@ -90,12 +90,13 @@ public: void insert(MySQL_Event* event); /** - * @brief Retrieves all events from the circular buffer. - * @return A deque containing all the events in the buffer. The caller takes ownership of the events and is responsible for deleting them. + * @brief Retrieves all events from the circular buffer and populates a provided vector. + * @param events A reference to a vector that will be populated with the events from the buffer. The caller takes ownership of the events and is responsible for deleting them. * - * This method clears the buffer after retrieving the events. + * This method clears the buffer after retrieving the events. The function reserves space in the vector to avoid unnecessary reallocations. */ - std::deque get_all_events(); + void get_all_events(std::vector& events); + /** * @brief Gets the current size of the buffer. diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index c67fb9656..f8a999df6 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -1163,10 +1163,11 @@ void MySQL_Logger_CircularBuffer::insert(MySQL_Event* event) { event_buffer.push_back(event); } -std::deque MySQL_Logger_CircularBuffer::get_all_events() { +void MySQL_Logger_CircularBuffer::get_all_events(std::vector& events) { std::lock_guard lock(mutex); - std::deque events = std::move(event_buffer); - return events; + events.reserve(event_buffer.size()); + events.insert(events.end(), event_buffer.begin(), event_buffer.end()); + event_buffer.clear(); } size_t MySQL_Logger_CircularBuffer::getBufferSize() const {