From 4fe41b69fd08f3f1239bfbf8961c41476cde59da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chojnowski?= Date: Fri, 27 Nov 2020 12:47:58 +0100 Subject: [PATCH] types: validate tuples without linearizing We can validate tuples directly from fragmented buffers now. --- types.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/types.cc b/types.cc index 3667c44c82..4211243e4d 100644 --- a/types.cc +++ b/types.cc @@ -1401,16 +1401,15 @@ tuple_type_impl::get_instance(std::vector types) { return intern::get_instance(std::move(types)); } -static void validate_aux(const tuple_type_impl& t, bytes_view v, cql_serialization_format sf) { +template +static void validate_aux(const tuple_type_impl& t, View v, cql_serialization_format sf) { auto ti = t.all_types().begin(); - auto vi = tuple_deserializing_iterator::start(v); - auto end = tuple_deserializing_iterator::finish(v); - while (ti != t.all_types().end() && vi != end) { - if (*vi) { - (*ti)->validate(**vi, sf); + while (ti != t.all_types().end() && v.size_bytes()) { + std::optional e = read_tuple_element(v); + if (e) { + (*ti)->validate(*e, sf); } ++ti; - ++vi; } } @@ -1577,9 +1576,7 @@ struct validate_visitor { }); } void operator()(const tuple_type_impl& t) { - with_linearized(v, [this, &t] (bytes_view bv) { - validate_aux(t, bv, sf); - }); + validate_aux(t, v, sf); } }; }