From 20d1c280a77eadcea18438453dc37daaf1d85e2d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 13 Oct 2023 11:13:20 +1100 Subject: Remove templating of Continuation --- src/database/database.cpp | 73 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'src/database/database.cpp') diff --git a/src/database/database.cpp b/src/database/database.cpp index ad81cfcf..9d29aea8 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -355,23 +355,23 @@ auto Database::GetTracksByIndex(const IndexInfo& index, std::size_t page_size) .components_hash = 0, }; OwningSlice prefix = EncodeIndexPrefix(header); - Continuation c{.prefix = prefix.data, - .start_key = prefix.data, - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = prefix.data, + .start_key = prefix.data, + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } auto Database::GetTracks(std::size_t page_size) -> std::future*> { return worker_task_->Dispatch*>([=, this]() -> Result* { - Continuation c{.prefix = EncodeDataPrefix().data, - .start_key = EncodeDataPrefix().data, - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = EncodeDataPrefix().data, + .start_key = EncodeDataPrefix().data, + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } @@ -379,28 +379,27 @@ auto Database::GetDump(std::size_t page_size) -> std::future*> { return worker_task_->Dispatch*>( [=, this]() -> Result* { - Continuation c{.prefix = "", - .start_key = "", - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = "", + .start_key = "", + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } template -auto Database::GetPage(Continuation* c) -> std::future*> { - Continuation copy = *c; +auto Database::GetPage(Continuation* c) -> std::future*> { + Continuation copy = *c; return worker_task_->Dispatch*>( - [=, this]() -> Result* { return dbGetPage(copy); }); + [=, this]() -> Result* { return dbGetPage(copy); }); } -template auto Database::GetPage(Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; -template auto Database::GetPage(Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; -template auto Database::GetPage( - Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; auto Database::dbMintNewTrackId() -> TrackId { @@ -477,7 +476,7 @@ auto Database::dbCreateIndexesForTrack(const Track& track) -> void { } template -auto Database::dbGetPage(const Continuation& c) -> Result* { +auto Database::dbGetPage(const Continuation& c) -> Result* { // Work out our starting point. Sometimes this will already done. std::unique_ptr it{ db_->NewIterator(leveldb::ReadOptions{})}; @@ -524,13 +523,13 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { } // Work out the new continuations. - std::optional> next_page; + std::optional next_page; if (c.forward) { if (it != nullptr) { // We were going forward, and now we want the next page. std::pmr::string key{it->key().data(), it->key().size(), &memory::kSpiRamResource}; - next_page = Continuation{ + next_page = Continuation{ .prefix = c.prefix, .start_key = key, .forward = true, @@ -543,7 +542,7 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { // We were going backwards, and now we want the next page. This is a // reversal, to set the start key to the first record we saw and mark that // it's off by one. - next_page = Continuation{ + next_page = Continuation{ .prefix = c.prefix, .start_key = *first_key, .forward = true, @@ -552,11 +551,11 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { }; } - std::optional> prev_page; + std::optional prev_page; if (c.forward) { // We were going forwards, and now we want the previous page. Set the search // key to the first result we saw, and mark that it's off by one. - prev_page = Continuation{ + prev_page = Continuation{ .prefix = c.prefix, .start_key = *first_key, .forward = false, @@ -568,7 +567,7 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { // We were going backwards, and we still want to go backwards. std::pmr::string key{it->key().data(), it->key().size(), &memory::kSpiRamResource}; - prev_page = Continuation{ + prev_page = Continuation{ .prefix = c.prefix, .start_key = key, .forward = false, @@ -582,10 +581,10 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { return new Result(std::move(records), next_page, prev_page); } -template auto Database::dbGetPage(const Continuation& c) +template auto Database::dbGetPage(const Continuation& c) -> Result*; -template auto Database::dbGetPage( - const Continuation& c) -> Result*; +template auto Database::dbGetPage(const Continuation& c) + -> Result*; template <> auto Database::ParseRecord(const leveldb::Slice& key, @@ -668,13 +667,13 @@ auto IndexRecord::track() const -> std::optional { } auto IndexRecord::Expand(std::size_t page_size) const - -> std::optional> { + -> std::optional { if (track_) { return {}; } IndexKey::Header new_header = ExpandHeader(key_.header, key_.item); OwningSlice new_prefix = EncodeIndexPrefix(new_header); - return Continuation{ + return Continuation{ .prefix = new_prefix.data, .start_key = new_prefix.data, .forward = true, -- cgit v1.2.3