From be19040eee21c05af52e1dc787247da77f057089 Mon Sep 17 00:00:00 2001 From: Ben Pope Date: Sat, 3 Jun 2023 01:07:03 +0100 Subject: [PATCH] utils/fragmented_vector: Remove assignment from std::vector Assignment from `std::vector` was introduced in #8469. Now that kafka/protocol/generator can call kafka::protocol::read_array, this is no longer needed, avoiding a large copy. Signed-off-by: Ben Pope --- .../tests/tx_range_manifest_test.cc | 15 ++++++++++++--- src/v/utils/fragmented_vector.h | 13 ------------- src/v/utils/tests/fragmented_vector_test.cc | 17 ----------------- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/v/cloud_storage/tests/tx_range_manifest_test.cc b/src/v/cloud_storage/tests/tx_range_manifest_test.cc index e7d3fb7e5deac..8a75a2b5426eb 100644 --- a/src/v/cloud_storage/tests/tx_range_manifest_test.cc +++ b/src/v/cloud_storage/tests/tx_range_manifest_test.cc @@ -41,7 +41,17 @@ static remote_manifest_path using tx_range_t = model::tx_range; -static std::vector ranges = { +template +static fragmented_vector +make_fragmented_vector(std::initializer_list in) { + fragmented_vector 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), @@ -78,8 +88,7 @@ SEASTAR_THREAD_TEST_CASE(empty_serialization_roundtrip_test) { } SEASTAR_THREAD_TEST_CASE(serialization_roundtrip_test) { - fragmented_vector tx_ranges; - tx_ranges = ranges; + fragmented_vector tx_ranges = make_fragmented_vector(ranges); tx_range_manifest m(segment_path, std::move(tx_ranges)); auto [is, size] = m.serialize().get(); iobuf buf; diff --git a/src/v/utils/fragmented_vector.h b/src/v/utils/fragmented_vector.h index 56b91dc1dc3c2..c7d433e2aa515 100644 --- a/src/v/utils/fragmented_vector.h +++ b/src/v/utils/fragmented_vector.h @@ -207,19 +207,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& rhs) noexcept { - clear(); - - for (auto& e : rhs) { - push_back(e); - } - - return *this; - } - /** * Remove all elements from the vector. * diff --git a/src/v/utils/tests/fragmented_vector_test.cc b/src/v/utils/tests/fragmented_vector_test.cc index cf17d69ee0823..2d1d68fefecec 100644 --- a/src/v/utils/tests/fragmented_vector_test.cc +++ b/src/v/utils/tests/fragmented_vector_test.cc @@ -335,23 +335,6 @@ BOOST_AUTO_TEST_CASE(fragmented_vector_vector_clear) { v = make({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 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}))); } BOOST_AUTO_TEST_CASE(fragmented_vector_pop_back_n) {