Skip to content

Commit

Permalink
Merge ' sstables: consumer: reuse the fragmented_temporary_buffer in …
Browse files Browse the repository at this point in the history
…read_bytes()' from Michał Chojnowski

primitive_consumer::read_bytes() destroys and creates a vector for every value it reads.
This happens for every cell.
We can save a bit of work by reusing the vector.

Closes scylladb#10512

* github.com:scylladb/scylla:
  sstables: consumer: reuse the fragmented_temporary_buffer in read_bytes()
  utils: fragmented_temporary_buffer: add release()
  • Loading branch information
avikivity committed May 8, 2022
2 parents 8e99d39 + ddc535a commit 287c01a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sstables/consumer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ public:
}
inline read_status read_bytes(temporary_buffer<char>& data, uint32_t len, fragmented_temporary_buffer& where) {
if (data.size() >= len) {
std::vector<temporary_buffer<char>> fragments;
fragments.push_back(data.share(0,len));
auto fragments = std::move(where).release();
fragments.clear();
fragments.push_back(data.share(0, len));
where = fragmented_temporary_buffer(std::move(fragments), len);
data.trim_front(len);
return read_status::ready;
Expand Down
4 changes: 4 additions & 0 deletions utils/fragmented_temporary_buffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public:
}
return fragmented_temporary_buffer(std::move(fragments), data_size);
}

vector_type release() && noexcept {
return std::move(_fragments);
}
};

class fragmented_temporary_buffer::view {
Expand Down

0 comments on commit 287c01a

Please sign in to comment.