From abe6c2d3d2b23cc7c843ca1cea0fd431fc10f589 Mon Sep 17 00:00:00 2001 From: Kamil Braun Date: Mon, 21 Oct 2019 10:16:05 +0200 Subject: [PATCH] types: introduce to_bytes_opt_vec function. It converts a vector to a vector. Used in a bunch of places. --- cql3/tuples.cc | 11 ++--------- cql3/tuples.hh | 6 ++---- types.cc | 9 +++++++++ types.hh | 2 ++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cql3/tuples.cc b/cql3/tuples.cc index 053de3897c..65ad2b32d5 100644 --- a/cql3/tuples.cc +++ b/cql3/tuples.cc @@ -92,15 +92,8 @@ tuples::in_value::from_serialized(const fragmented_temporary_buffer::view& value std::vector> elements; elements.reserve(l.size()); - for (auto&& element : l) { - auto tuple_buff = ttype->decompose(element); - auto tuple = ttype->split(tuple_buff); - std::vector elems; - elems.reserve(tuple.size()); - for (auto&& e : tuple) { - elems.emplace_back(to_bytes_opt(e)); - } - elements.emplace_back(std::move(elems)); + for (auto&& e : l) { + elements.emplace_back(to_bytes_opt_vec(ttype->split(ttype->decompose(e)))); } return tuples::in_value(elements); }); diff --git a/cql3/tuples.hh b/cql3/tuples.hh index c5172a2cd0..208364bac5 100644 --- a/cql3/tuples.hh +++ b/cql3/tuples.hh @@ -112,10 +112,8 @@ public: value(std::vector elements) : _elements(std::move(elements)) { } - value(std::vector elements) { - for (auto&& e : elements) { - _elements.push_back(e ? bytes_opt(bytes(e->begin(), e->size())) : bytes_opt()); - } + value(std::vector elements) + : value(to_bytes_opt_vec(std::move(elements))) { } static value from_serialized(const fragmented_temporary_buffer::view& buffer, const tuple_type_impl& type) { return with_linearized(buffer, [&] (bytes_view view) { diff --git a/types.cc b/types.cc index 0d4c680c21..25ecf231cb 100644 --- a/types.cc +++ b/types.cc @@ -96,6 +96,15 @@ sstring inet_to_string(const seastar::net::inet_address& addr) { return out.str(); } +std::vector to_bytes_opt_vec(const std::vector& v) { + std::vector r; + r.reserve(v.size()); + for (auto& e: v) { + r.push_back(to_bytes_opt(e)); + } + return r; +} + static const char* byte_type_name = "org.apache.cassandra.db.marshal.ByteType"; static const char* short_type_name = "org.apache.cassandra.db.marshal.ShortType"; static const char* int32_type_name = "org.apache.cassandra.db.marshal.Int32Type"; diff --git a/types.hh b/types.hh index e98c6c75c9..76c88296d4 100644 --- a/types.hh +++ b/types.hh @@ -1055,6 +1055,8 @@ to_bytes_opt(bytes_view_opt bv) { return std::nullopt; } +std::vector to_bytes_opt_vec(const std::vector&); + inline bytes_view_opt as_bytes_view_opt(const bytes_opt& bv) {