From 0d9488eae645b97ff18a36a06baa78eb7f675eaa Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 14 Mar 2018 11:58:03 -0400 Subject: [PATCH] sstables: replace potentially large for loop with do_until We are pushing ints here, so it shouldn't be that bad in practice. But a potentially gigantic for loop is just asking for a stall since we won't need_preempt() it. Signed-off-by: Glauber Costa --- sstables/sstables.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 7889c489e2..780da4b38f 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -646,22 +646,23 @@ future<> parse(random_access_reader& in, summary& s) { check_buf_size(buf, len); s.entries.resize(s.header.size); - // Positions are encoded in little-endian. auto b = buf.get(); s.positions = utils::chunked_vector(); - for (size_t i = 0; i < s.header.size; ++i) { + return do_until([&s] { return s.positions.size() == s.header.size; }, [&s, b] () mutable { s.positions.push_back(seastar::read_le(b)); b += sizeof(pos_type); - } - - // Since the keys in the index are not sized, we need to calculate - // the start position of the index i+1 to determine the boundaries - // of index i. The "memory_size" field in the header determines the - // total memory used by the map, so if we push it to the vector, we - // can guarantee that no conditionals are used, and we can always - // query the position of the "next" index. - s.positions.push_back(s.header.memory_size); + return make_ready_future<>(); + }).then([&s] { + // Since the keys in the index are not sized, we need to calculate + // the start position of the index i+1 to determine the boundaries + // of index i. The "memory_size" field in the header determines the + // total memory used by the map, so if we push it to the vector, we + // can guarantee that no conditionals are used, and we can always + // query the position of the "next" index. + s.positions.push_back(s.header.memory_size); + return make_ready_future<>(); + }); }).then([&in, &s] { in.seek(sizeof(summary::header) + s.header.memory_size); return parse(in, s.first_key, s.last_key);