mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
modificiation_statement: Use result_view::do_with()
Reduces code duplication. Message-Id: <1458336592-22065-1-git-send-email-tgrabiec@scylladb.com>
This commit is contained in:
committed by
Avi Kivity
parent
6d031b4c6b
commit
c518e852ee
@@ -291,13 +291,11 @@ modification_statement::read_required_rows(
|
||||
query::read_command cmd(s->id(), s->version(), ps, std::numeric_limits<uint32_t>::max());
|
||||
// FIXME: ignoring "local"
|
||||
return proxy.local().query(s, make_lw_shared(std::move(cmd)), std::move(pr), cl).then([this, ps] (auto result) {
|
||||
// FIXME: copying
|
||||
// FIXME: Use scattered_reader to avoid copying
|
||||
bytes_ostream buf(result->buf());
|
||||
query::result_view v(buf.linearize());
|
||||
auto prefetched_rows = update_parameters::prefetched_rows_type({update_parameters::prefetch_data(s)});
|
||||
v.consume(ps, prefetch_data_builder(s, prefetched_rows.value(), ps));
|
||||
return prefetched_rows;
|
||||
return query::result_view::do_with(*result, [&] (query::result_view v) {
|
||||
auto prefetched_rows = update_parameters::prefetched_rows_type({update_parameters::prefetch_data(s)});
|
||||
v.consume(ps, prefetch_data_builder(s, prefetched_rows.value(), ps));
|
||||
return prefetched_rows;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -143,17 +143,17 @@ public:
|
||||
result_view(ser::query_result_view v) : _v(v) {}
|
||||
|
||||
template <typename Func>
|
||||
static void do_with(const query::result& res, Func&& func) {
|
||||
static auto do_with(const query::result& res, Func&& func) {
|
||||
const bytes_ostream& buf = res.buf();
|
||||
// FIXME: This special casing saves us the cost of copying an already
|
||||
// linearized response. When we switch views to scattered_reader this will go away.
|
||||
if (buf.is_linearized()) {
|
||||
result_view view(buf.view());
|
||||
func(view);
|
||||
return func(view);
|
||||
} else {
|
||||
bytes_ostream w(buf);
|
||||
result_view view(w.linearize());
|
||||
func(view);
|
||||
return func(view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user