From 8a6f362ef864dbac6d7232bf8c57ef4d84efef89 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Fri, 5 Jun 2015 15:26:21 -0400 Subject: [PATCH] sstables: dowithify non dowithed code Technically speaking, the current code is not wrong. However, it was written before we had do_with, and I ended up dowithing it while chasing our erratic bug under the suspicion that this code could somehow be related with our bug. Turns out it isn't, but now that I went through the trouble of dowithing it - and since do_with is easier to reason about and guarantee liveness, let's go with this option. Signed-off-by: Glauber Costa Reviewed-by: Pekka Enberg --- sstables/sstables.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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); + }); + }); }); }); }