Skip to content

Commit

Permalink
utils/fragmented_vector: Remove assignment from std::vector
Browse files Browse the repository at this point in the history
Assignment from `std::vector` was introduced in redpanda-data#8469.

Now that kafka/protocol/generator can call
kafka::protocol::read_array<fragmented_vector>, this is no
longer needed, avoiding a large copy.

Signed-off-by: Ben Pope <[email protected]>
  • Loading branch information
BenPope committed Jul 17, 2023
1 parent ae21a81 commit 9dd4c53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
15 changes: 12 additions & 3 deletions src/v/cloud_storage/tests/tx_range_manifest_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ static remote_manifest_path

using tx_range_t = model::tx_range;

static std::vector<tx_range_t> ranges = {
template<typename T = int>
static fragmented_vector<T>
make_fragmented_vector(std::initializer_list<T> in) {
fragmented_vector<T> ret;
for (auto& e : in) {
ret.push_back(e);
}
return ret;
}

static auto ranges = {
tx_range_t{
.pid = model::producer_identity(1, 2),
.first = model::offset(3),
Expand Down Expand Up @@ -78,8 +88,7 @@ SEASTAR_THREAD_TEST_CASE(empty_serialization_roundtrip_test) {
}

SEASTAR_THREAD_TEST_CASE(serialization_roundtrip_test) {
fragmented_vector<tx_range_t> tx_ranges;
tx_ranges = ranges;
fragmented_vector<tx_range_t> tx_ranges = make_fragmented_vector(ranges);
tx_range_manifest m(segment_path, std::move(tx_ranges));
auto [is, size] = m.serialize().get();
iobuf buf;
Expand Down
13 changes: 0 additions & 13 deletions src/v/utils/fragmented_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,6 @@ class fragmented_vector {
*/
static size_t elements_per_fragment() { return elems_per_frag; }

/**
* Assign from a std::vector.
*/
fragmented_vector& operator=(const std::vector<T>& rhs) noexcept {
clear();

for (auto& e : rhs) {
push_back(e);
}

return *this;
}

/**
* Remove all elements from the vector.
*
Expand Down
17 changes: 0 additions & 17 deletions src/v/utils/tests/fragmented_vector_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,4 @@ BOOST_AUTO_TEST_CASE(fragmented_vector_vector_clear) {

v = make<int, 8>({5, 5, 5, 5});
BOOST_CHECK_EQUAL(v->size(), 4);

v.u = std::vector{1, 2, 3};
BOOST_CHECK_EQUAL(v->size(), 3);
}

BOOST_AUTO_TEST_CASE(fragmented_vector_vector_assign) {
std::vector vin0{1, 2, 3};
std::vector vin1{4, 5};

checker<int, 8> v;
BOOST_CHECK_EQUAL(v, (make({})));

v.get() = std::vector{1};
BOOST_CHECK_EQUAL(v, (make({1})));

v.get() = std::vector{2, 3, 4};
BOOST_CHECK_EQUAL(v, (make({2, 3, 4})));
}

0 comments on commit 9dd4c53

Please sign in to comment.