From 9867cdee10d8d46e94f31f25fb2cab6fe7cd33c7 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 4 Sep 2018 19:48:49 +0100 Subject: [PATCH] Remove Plugin::GetLowercasedName() It should only be used in certain cases, so to avoid misuse don't have it as a method on the object. --- src/api/game/game_cache.cpp | 6 ++++-- src/api/game/game_cache.h | 10 +++++++++- src/api/plugin.cpp | 6 +----- src/api/plugin.h | 1 - 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/api/game/game_cache.cpp b/src/api/game/game_cache.cpp index 34479949..df5e8ec1 100644 --- a/src/api/game/game_cache.cpp +++ b/src/api/game/game_cache.cpp @@ -109,11 +109,13 @@ std::optional> GameCache::GetPlugin( void GameCache::AddPlugin(const Plugin&& plugin) { lock_guard lock(mutex_); - auto it = plugins_.find(plugin.GetLowercasedName()); + auto lowercasedName = to_lower(plugin.GetName()); + + auto it = plugins_.find(lowercasedName); if (it != end(plugins_)) plugins_.erase(it); - plugins_.emplace(plugin.GetLowercasedName(), + plugins_.emplace(lowercasedName, std::make_shared(std::move(plugin))); } diff --git a/src/api/game/game_cache.h b/src/api/game/game_cache.h index cf7a3545..8b392121 100644 --- a/src/api/game/game_cache.h +++ b/src/api/game/game_cache.h @@ -73,7 +73,15 @@ template<> struct less> { bool operator()(const std::shared_ptr& lhs, const std::shared_ptr& rhs) const { - return lhs->GetLowercasedName() < rhs->GetLowercasedName(); + if (!lhs) { + return false; + } + + if (!rhs) { + return true; + } + + return *lhs < *rhs; } }; } diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 7bedb3dd..692e1600 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -131,10 +131,6 @@ Plugin::Plugin(const GameType gameType, std::string Plugin::GetName() const { return name_; } -std::string Plugin::GetLowercasedName() const { - return boost::locale::to_lower(name_); -} - std::optional Plugin::GetVersion() const { std::string version = Version(GetDescription()).AsString(); if (version.empty()) { @@ -263,7 +259,7 @@ uintmax_t Plugin::GetFileSize(std::filesystem::path pluginPath) { } bool Plugin::operator<(const Plugin& rhs) const { - return GetLowercasedName() < rhs.GetLowercasedName(); + return boost::locale::to_lower(name_) < boost::locale::to_lower(rhs.name_); } bool Plugin::IsActive() const { return isActive_; } diff --git a/src/api/plugin.h b/src/api/plugin.h index 9c82fb28..1be0317a 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -50,7 +50,6 @@ public: const bool headerOnly); std::string GetName() const; - std::string GetLowercasedName() const; std::optional GetVersion() const; std::vector GetMasters() const; std::set GetBashTags() const;