Skip to content

Commit 675954e

Browse files
authored
Merge pull request #40 from arvidn/poll-batch-performance
improve performance of Consumer::poll_batch()
2 parents deff8b1 + 98b9839 commit 675954e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/consumer.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ vector<Message> Consumer::poll_batch(size_t max_batch_size, milliseconds timeout
214214
raw_messages.size());
215215
if (result == -1) {
216216
check_error(rd_kafka_last_error());
217+
// on the off-chance that check_error() does not throw an error
218+
result = 0;
217219
}
218220
vector<Message> output;
221+
raw_messages.resize(result);
222+
output.reserve(result);
219223
for (const auto ptr : raw_messages) {
220-
if (ptr) {
221-
output.emplace_back(ptr);
222-
}
224+
output.emplace_back(ptr);
223225
}
224226
return output;
225227
}

0 commit comments

Comments
 (0)