From 05a7869d0861ca6ab6943ad6a70f6918e96306f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 25 May 2021 17:55:19 -0400 Subject: [PATCH] isMessageTreated: use string_view Change-Id: I477530d34d91923864b6ee772a00765a92fd2ffe --- src/jamidht/jamiaccount.cpp | 12 ++++++------ src/jamidht/jamiaccount.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 9afee70c80..20bf288864 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2602,10 +2602,10 @@ JamiAccount::getCertificatesByStatus(tls::TrustStore::PermissionStatus status) } template<typename ID = dht::Value::Id> -std::set<ID> +std::set<ID, std::less<>> loadIdList(const std::string& path) { - std::set<ID> ids; + std::set<ID, std::less<>> ids; std::ifstream file = fileutils::ifstream(path); if (!file.is_open()) { JAMI_DBG("Could not load %s", path.c_str()); @@ -2626,9 +2626,9 @@ loadIdList(const std::string& path) return ids; } -template<typename ID = dht::Value::Id> +template<typename List = std::set<dht::Value::Id>> void -saveIdList(const std::string& path, const std::set<ID>& ids) +saveIdList(const std::string& path, const List& ids) { std::ofstream file = fileutils::ofstream(path, std::ios::trunc | std::ios::binary); if (!file.is_open()) { @@ -2660,14 +2660,14 @@ JamiAccount::saveTreatedMessages() const auto& this_ = *sthis; std::lock_guard<std::mutex> lock(this_.messageMutex_); fileutils::check_dir(this_.cachePath_.c_str()); - saveIdList<std::string>(this_.cachePath_ + DIR_SEPARATOR_STR "treatedMessages", + saveIdList<decltype(this_.treatedMessages_)>(this_.cachePath_ + DIR_SEPARATOR_STR "treatedMessages", this_.treatedMessages_); } }); } bool -JamiAccount::isMessageTreated(const std::string& id) +JamiAccount::isMessageTreated(std::string_view id) { std::lock_guard<std::mutex> lock(messageMutex_); auto res = treatedMessages_.emplace(id); diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index e6ccbe0734..c41ee250e7 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -390,7 +390,7 @@ public: /// \return true if the given DHT message identifier has been treated /// \note if message has not been treated yet this method store this id and returns true at /// further calls - bool isMessageTreated(const std::string& id); + bool isMessageTreated(std::string_view id); std::shared_ptr<dht::DhtRunner> dht() { return dht_; } @@ -727,7 +727,7 @@ private: mutable std::mutex messageMutex_ {}; std::map<dht::Value::Id, PendingMessage> sentMessages_; - std::set<std::string> treatedMessages_ {}; + std::set<std::string, std::less<>> treatedMessages_ {}; std::string deviceName_ {}; std::string idPath_ {}; -- GitLab