From 4f4a54abda994362859c23592efaebba30c31a71 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 6 Mar 2020 09:50:45 -0800 Subject: [PATCH] ncm: inline getlatestkey --- .../ncm/ncm_content_meta_database_impl.cpp | 47 +++++++++---------- .../ncm/ncm_content_meta_database_impl.hpp | 1 - ...m_on_memory_content_meta_database_impl.cpp | 43 ++++++++--------- ...m_on_memory_content_meta_database_impl.hpp | 1 - 4 files changed, 40 insertions(+), 52 deletions(-) diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp index c2ee94de0..d72718c73 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp @@ -49,31 +49,6 @@ namespace ams::ncm { return ResultSuccess(); } - Result ContentMetaDatabaseImpl::GetLatestKeyImpl(ContentMetaKey *out_key, u64 id) const { - R_TRY(this->EnsureEnabled()); - - std::optional found_key = std::nullopt; - - /* Find the last key with the desired program id. */ - for (auto entry = this->kvs->lower_bound(ContentMetaKey::MakeUnknownType(id, 0)); entry != this->kvs->end(); entry++) { - /* No further entries will match the program id, discontinue. */ - if (entry->GetKey().id != id) { - break; - } - - /* We are only interested in keys with the Full content install type. */ - if (entry->GetKey().install_type == ContentInstallType::Full) { - found_key = entry->GetKey(); - } - } - - /* Check if the key is absent. */ - R_UNLESS(found_key, ncm::ResultContentMetaNotFound()); - - *out_key = *found_key; - return ResultSuccess(); - } - Result ContentMetaDatabaseImpl::Set(const ContentMetaKey &key, sf::InBuffer value) { R_TRY(this->EnsureEnabled()); return this->kvs->Set(key, value.GetPointer(), value.GetSize()); @@ -173,7 +148,27 @@ namespace ams::ncm { Result ContentMetaDatabaseImpl::GetLatestContentMetaKey(sf::Out out_key, u64 id) { R_TRY(this->EnsureEnabled()); - return this->GetLatestKeyImpl(out_key.GetPointer(), id); + + std::optional found_key = std::nullopt; + + /* Find the last key with the desired program id. */ + for (auto entry = this->kvs->lower_bound(ContentMetaKey::MakeUnknownType(id, 0)); entry != this->kvs->end(); entry++) { + /* No further entries will match the program id, discontinue. */ + if (entry->GetKey().id != id) { + break; + } + + /* We are only interested in keys with the Full content install type. */ + if (entry->GetKey().install_type == ContentInstallType::Full) { + found_key = entry->GetKey(); + } + } + + /* Check if the key is absent. */ + R_UNLESS(found_key, ncm::ResultContentMetaNotFound()); + + out_key.SetValue(*found_key); + return ResultSuccess(); } Result ContentMetaDatabaseImpl::ListApplication(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_keys, ContentMetaType type) { diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp index a03ef5152..180c1c481 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp @@ -26,7 +26,6 @@ namespace ams::ncm { private: /* Helpers. */ Result GetContentIdImpl(ContentId *out, const ContentMetaKey& key, ContentType type, std::optional id_offset) const; - Result GetLatestKeyImpl(ContentMetaKey *out_key, u64 id) const; public: /* Actual commands. */ virtual Result Set(const ContentMetaKey &key, sf::InBuffer value) override; diff --git a/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.cpp index 3a1d2603d..21af7d6ea 100644 --- a/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.cpp @@ -18,29 +18,6 @@ namespace ams::ncm { - Result ContentMetaDatabaseImpl::GetLatestKeyImpl(ContentMetaKey *out_key, u64 id) const { - R_TRY(this->EnsureEnabled()); - - std::optional found_key = std::nullopt; - - /* Find the last key with the desired program id. */ - for (auto entry = this->kvs->lower_bound(ContentMetaKey::MakeUnknownType(id, 0)); entry != this->kvs->end(); entry++) { - /* No further entries will match the program id, discontinue. */ - if (entry->GetKey().id != id) { - break; - } - - /* On memory content database is interested in all keys. */ - found_key = entry->GetKey(); - } - - /* Check if the key is absent. */ - R_UNLESS(found_key, ncm::ResultContentMetaNotFound()); - - *out_key = *found_key; - return ResultSuccess(); - } - Result OnMemoryContentMetaDatabaseImpl::List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) { /* NOTE: This function is *almost* identical to the ContentMetaDatabaseImpl equivalent. */ /* The only difference is that the min max comparison is exclusive for OnMemoryContentMetaDatabaseImpl, */ @@ -89,7 +66,25 @@ namespace ams::ncm { Result OnMemoryContentMetaDatabaseImpl::GetLatestContentMetaKey(sf::Out out_key, u64 id) { R_TRY(this->EnsureEnabled()); - return this->GetLatestKeyImpl(out_key.GetPointer(), id); + + std::optional found_key = std::nullopt; + + /* Find the last key with the desired program id. */ + for (auto entry = this->kvs->lower_bound(ContentMetaKey::MakeUnknownType(id, 0)); entry != this->kvs->end(); entry++) { + /* No further entries will match the program id, discontinue. */ + if (entry->GetKey().id != id) { + break; + } + + /* On memory content database is interested in all keys. */ + found_key = entry->GetKey(); + } + + /* Check if the key is absent. */ + R_UNLESS(found_key, ncm::ResultContentMetaNotFound()); + + out_key.SetValue(*found_key); + return ResultSuccess(); } Result OnMemoryContentMetaDatabaseImpl::LookupOrphanContent(const sf::OutArray &out_orphaned, const sf::InArray &content_ids) { diff --git a/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.hpp index b298baa2c..9d2c88893 100644 --- a/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_on_memory_content_meta_database_impl.hpp @@ -22,7 +22,6 @@ namespace ams::ncm { class OnMemoryContentMetaDatabaseImpl : public ContentMetaDatabaseImpl { public: OnMemoryContentMetaDatabaseImpl(ams::kvdb::MemoryKeyValueStore *kvs) : ContentMetaDatabaseImpl(kvs) { /* ... */ } - Result GetLatestKeyImpl(ContentMetaKey *out_key, u64 id) const; public: /* Actual commands. */ virtual Result List(sf::Out out_entries_total, sf::Out out_entries_written, const sf::OutArray &out_info, ContentMetaType meta_type, ApplicationId application_id, u64 min, u64 max, ContentInstallType install_type) override;