Skip to content

Commit

Permalink
fragmented_vector: call reserve for iterator constructor
Browse files Browse the repository at this point in the history
The dynamic variant will now remove a couple of extra allocations.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
  • Loading branch information
rockwotj committed Feb 6, 2024
1 parent aa9507b commit 9f8e7ec
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/v/container/include/container/fragmented_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ class fragmented_vector {
requires std::input_iterator<Iter>
fragmented_vector(Iter begin, Iter end)
: fragmented_vector() {
if constexpr (std::random_access_iterator<Iter>) {
reserve(std::distance(begin, end));
}
// Improvement: Write a more efficient implementation for
// random_access_iterators
// std::contiguous_iterator<Iter>
for (auto it = begin; it != end; ++it) {
push_back(*it);
}
Expand Down

0 comments on commit 9f8e7ec

Please sign in to comment.