mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
utils/fragmented_temporary_buffer: simplify allocate_to_fit()
1) reuse default_fragment_size for knowledge of max fragment size 2) fragments_count is not a good name as it doesn't include last non-full fragment (if present), so rename it. 3) simplify calculation of last fragment size Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com> Message-Id: <20210129231532.871405-1-raphaelsc@scylladb.com>
This commit is contained in:
committed by
Avi Kivity
parent
575c992a35
commit
08e838d4b5
@@ -97,13 +97,13 @@ public:
|
||||
// Creates a fragmented temporary buffer of a specified size, supplied as a parameter.
|
||||
// Max chunk size is limited to 128kb (the same limit as `bytes_stream` has).
|
||||
static fragmented_temporary_buffer allocate_to_fit(size_t data_size) {
|
||||
constexpr size_t max_fragment_size = 128 * 1024; // 128KB
|
||||
constexpr size_t max_fragment_size = default_fragment_size; // 128KB
|
||||
|
||||
const size_t fragments_count = data_size / max_fragment_size; // number of max-sized fragments
|
||||
const size_t last_fragment_size = data_size - (fragments_count * max_fragment_size);
|
||||
const size_t full_fragment_count = data_size / max_fragment_size; // number of max-sized fragments
|
||||
const size_t last_fragment_size = data_size % max_fragment_size;
|
||||
|
||||
std::vector<seastar::temporary_buffer<char>> fragments;
|
||||
for (size_t i = 0; i < fragments_count; ++i) {
|
||||
for (size_t i = 0; i < full_fragment_count; ++i) {
|
||||
fragments.emplace_back(seastar::temporary_buffer<char>(max_fragment_size));
|
||||
}
|
||||
fragments.emplace_back(seastar::temporary_buffer<char>(last_fragment_size));
|
||||
|
||||
Reference in New Issue
Block a user