From 02b5c82832eb788a093af00973371d908751a61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 4 May 2024 23:49:27 +0200 Subject: [PATCH] Improve `fair_queue::next_batch ()` --- nano/node/fair_queue.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nano/node/fair_queue.hpp b/nano/node/fair_queue.hpp index d3ee9f453a..7cece03b3d 100644 --- a/nano/node/fair_queue.hpp +++ b/nano/node/fair_queue.hpp @@ -297,9 +297,10 @@ class fair_queue final std::deque next_batch (size_t max_count) { - // TODO: Naive implementation, could be optimized + auto count = std::min (size (), max_count); + std::deque result; - while (!empty () && result.size () < max_count) + while (result.size () < count) { result.emplace_back (next ()); }