diff --git a/sstables/sstables.cc b/sstables/sstables.cc index fccae9a906..bdaa8ed41d 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -389,19 +389,19 @@ future<> write(file_writer& out, disk_array& arr) { template future<> parse(random_access_reader& in, Size& len, std::unordered_map& map) { - auto count = make_lw_shared(); - auto eos = [len, count] { return len == *count; }; - return do_until(eos, [len, count, &in, &map] { - struct kv { - Key key; - Value value; - }; - ++*count; + return do_with(Size(), [&in, len, &map] (Size& count) { + auto eos = [len, &count] { return len == count++; }; + return do_until(eos, [len, &in, &map] { + struct kv { + Key key; + Value value; + }; - auto el = std::make_unique(); - auto f = parse(in, el->key, el->value); - return f.then([el = std::move(el), &map] { - map.emplace(el->key, el->value); + return do_with(kv(), [&in, &map] (auto& el) { + return parse(in, el.key, el.value).then([&el, &map] { + map.emplace(el.key, el.value); + }); + }); }); }); }