From d15dcccf7f8f9eff8ef4ee27346a9ce645cdf42b Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Wed, 25 Sep 2024 06:59:06 +0000 Subject: [PATCH] Improve code --- common/consumerstatetable.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/common/consumerstatetable.cpp b/common/consumerstatetable.cpp index b6e4993b..826970a4 100644 --- a/common/consumerstatetable.cpp +++ b/common/consumerstatetable.cpp @@ -43,25 +43,24 @@ void ConsumerStateTable::pops(std::deque &vkco, const st // Use poped_count to calculate and resize vkco queue after pop finished size_t not_poped_count = POP_BATCH_SIZE; size_t poped_count = 0; + size_t current_poped_count = 0; vkco.clear(); vkco.resize(not_poped_count); for(;;) { - if (not_poped_count <= SHA_POP_COMMAN_MAX_POP_SIZE) - { - poped_count += popsWithBatchSize(vkco, not_poped_count, poped_count); + current_poped_count = popsWithBatchSize(vkco, std::min(not_poped_count, SHA_POP_COMMAN_MAX_POP_SIZE), poped_count); + poped_count += current_poped_count; + not_poped_count -=current_poped_count; - // A call to resize with a smaller size does not invalidate any references to non-erased elements. - // https://en.cppreference.com/w/cpp/container/deque - vkco.resize(poped_count); - return; - } - else + if ((current_poped_count == 0) || (not_poped_count == 0)) { - poped_count += popsWithBatchSize(vkco, SHA_POP_COMMAN_MAX_POP_SIZE, poped_count); - not_poped_count -= SHA_POP_COMMAN_MAX_POP_SIZE; + break; } } + + // A call to resize with a smaller size does not invalidate any references to non-erased elements. + // https://en.cppreference.com/w/cpp/container/deque + vkco.resize(poped_count); } size_t ConsumerStateTable::popsWithBatchSize(std::deque &vkco, size_t popBatchSize, size_t queueStartIndex)