Reimplementation of MySQL_Logger_CircularBuffer::get_all_events()

Accept a reference to a vector instead of returning a deque
v2.x-logging_mem
René Cannaò 2 years ago
parent a8310f42a6
commit 754f1e52f2

@ -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<MySQL_Event*> get_all_events();
void get_all_events(std::vector<MySQL_Event*>& events);
/**
* @brief Gets the current size of the buffer.

@ -1163,10 +1163,11 @@ void MySQL_Logger_CircularBuffer::insert(MySQL_Event* event) {
event_buffer.push_back(event);
}
std::deque<MySQL_Event*> MySQL_Logger_CircularBuffer::get_all_events() {
void MySQL_Logger_CircularBuffer::get_all_events(std::vector<MySQL_Event*>& events) {
std::lock_guard<std::mutex> lock(mutex);
std::deque<MySQL_Event*> 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 {

Loading…
Cancel
Save