diff --git a/qt/Session.cc b/qt/Session.cc index 8646013da..f7992995c 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -516,9 +516,9 @@ void Session::torrentRenamePath(torrent_ids_t const& torrent_ids, QString const& q->run(); } -std::vector const& Session::getKeyNames(TorrentProperties props) +std::set const& Session::getKeyNames(TorrentProperties props) { - std::vector& names = names_[props]; + std::set& names = names_[props]; if (names.empty()) { @@ -609,7 +609,7 @@ std::vector const& Session::getKeyNames(TorrentProperties prop auto const append = [&names](tr_quark key) { - names.emplace_back(tr_quark_get_string_view(key)); + names.emplace(tr_quark_get_string_view(key)); }; switch (props) @@ -642,10 +642,6 @@ std::vector const& Session::getKeyNames(TorrentProperties prop // must be in every torrent req append(TR_KEY_id); - - // sort and remove dupes - std::sort(names.begin(), names.end()); - names.erase(std::unique(names.begin(), names.end()), names.end()); } return names; diff --git a/qt/Session.h b/qt/Session.h index 7ac6982e9..e00993db5 100644 --- a/qt/Session.h +++ b/qt/Session.h @@ -9,6 +9,7 @@ #include // int64_t #include #include +#include #include #include @@ -133,6 +134,26 @@ public: Rename }; + void addKeyName(TorrentProperties props, tr_quark const key) + { + // populate names cache with default values + if (names_[props].empty()) + { + getKeyNames(props); + } + + names_[props].emplace(tr_quark_get_string_view(key)); + } + + void removeKeyName(TorrentProperties props, tr_quark const key) + { + // do not remove id because it must be in every torrent req + if (key != TR_KEY_id) + { + names_[props].erase(tr_quark_get_string_view(key)); + } + } + public slots: void addTorrent(AddData add_me); void launchWebInterface() const; @@ -173,7 +194,7 @@ private: void pumpRequests(); void sendTorrentRequest(std::string_view request, torrent_ids_t const& torrent_ids); void refreshTorrents(torrent_ids_t const& ids, TorrentProperties props); - std::vector const& getKeyNames(TorrentProperties props); + std::set const& getKeyNames(TorrentProperties props); static void updateStats(tr_variant* args_dict, tr_session_stats* stats); @@ -182,7 +203,7 @@ private: QString const config_dir_; Prefs& prefs_; - std::map> names_; + std::map> names_; int64_t blocklist_size_ = -1; std::array port_test_pending_ = {};