cache_streamed_mutation: avoid moving clustering_row

clustering_row can stores quite a lot of data internally which makes its
move constructor not exactly cheap.
If possible it is better to move mutation_fragment around as it keeps
everything externally. This also avoids some cases when clustering row
would be extracted from mutation_fragment only to be made to create
another mutation_fragment later.
This commit is contained in:
Paweł Dziepak
2017-07-20 13:12:53 +01:00
parent 68e57a742f
commit 9bc6038ff3
2 changed files with 10 additions and 8 deletions

View File

@@ -110,7 +110,7 @@ class cache_streamed_mutation final : public streamed_mutation::impl {
// Emits all delayed range tombstones.
void drain_tombstones();
void add_to_buffer(const partition_snapshot_row_cursor&);
void add_to_buffer(clustering_row&&);
void add_clustering_row_to_buffer(mutation_fragment&&);
void add_to_buffer(range_tombstone&&);
void add_to_buffer(mutation_fragment&&);
future<> read_from_underlying();
@@ -419,7 +419,7 @@ void cache_streamed_mutation::drain_tombstones() {
inline
void cache_streamed_mutation::add_to_buffer(mutation_fragment&& mf) {
if (mf.is_clustering_row()) {
add_to_buffer(std::move(std::move(mf).as_clustering_row()));
add_clustering_row_to_buffer(std::move(mf));
} else {
assert(mf.is_range_tombstone());
add_to_buffer(std::move(mf).as_range_tombstone());
@@ -430,16 +430,17 @@ inline
void cache_streamed_mutation::add_to_buffer(const partition_snapshot_row_cursor& row) {
if (!row.dummy()) {
_read_context->cache().on_row_hit();
add_to_buffer(row.row());
add_clustering_row_to_buffer(row.row());
}
}
inline
void cache_streamed_mutation::add_to_buffer(clustering_row&& row) {
void cache_streamed_mutation::add_clustering_row_to_buffer(mutation_fragment&& mf) {
auto& row = mf.as_clustering_row();
drain_tombstones(row.position());
_last_row_key = row.key();
_lower_bound = position_in_partition::after_key(row.key());
push_mutation_fragment(std::move(row));
push_mutation_fragment(std::move(mf));
}
inline

View File

@@ -168,13 +168,14 @@ public:
const clustering_key& key() const { return _current_row[0].it->key(); }
// Can be called only when cursor is valid and pointing at a row.
clustering_row row() const {
mutation_fragment row() const {
auto it = _current_row.begin();
auto cr = clustering_row(*it->it);
auto mf = mutation_fragment(clustering_row(*it->it));
auto& cr = mf.as_mutable_clustering_row();
for (++it; it != _current_row.end(); ++it) {
cr.apply(_schema, *it->it);
}
return cr;
return mf;
}
// Can be called when cursor is pointing at a row, even when invalid.