diff --git a/gtk/.clang-tidy b/gtk/.clang-tidy index 2ba6e103f..82148826f 100644 --- a/gtk/.clang-tidy +++ b/gtk/.clang-tidy @@ -7,6 +7,7 @@ Checks: > -cppcoreguidelines-narrowing-conversions, modernize-*, -modernize-use-trailing-return-type, + performance-*, readability-*, -readability-function-cognitive-complexity, -readability-identifier-length, diff --git a/gtk/Actions.cc b/gtk/Actions.cc index 33caaca7a..da3b1aff8 100644 --- a/gtk/Actions.cc +++ b/gtk/Actions.cc @@ -112,7 +112,7 @@ Glib::RefPtr gtr_actions_init(Glib::RefPtr { myBuilder = builder.get(); - auto const action_group = Gio::SimpleActionGroup::create(); + auto action_group = Gio::SimpleActionGroup::create(); auto const match = gtr_pref_string_get(TR_KEY_sort_mode); diff --git a/gtk/FilterBar.cc b/gtk/FilterBar.cc index b912bb2e4..daa7a9024 100644 --- a/gtk/FilterBar.cc +++ b/gtk/FilterBar.cc @@ -288,7 +288,7 @@ bool tracker_filter_model_update(Glib::RefPtr const& tracker_mod Glib::RefPtr tracker_filter_model_new(Glib::RefPtr const& tmodel) { - auto const store = Gtk::TreeStore::create(tracker_filter_cols); + auto store = Gtk::TreeStore::create(tracker_filter_cols); auto iter = store->append(); iter->set_value(tracker_filter_cols.displayname, Glib::ustring(_("All"))); @@ -531,7 +531,7 @@ Glib::RefPtr activity_filter_model_new(Glib::RefPtr RemotePage::whitelist_tree_model_new(std::string const& whitelist) { - auto const store = Gtk::ListStore::create(whitelist_cols); + auto store = Gtk::ListStore::create(whitelist_cols); std::istringstream stream(whitelist); std::string s; diff --git a/gtk/Session.cc b/gtk/Session.cc index ad7ae9b38..3053cd76a 100644 --- a/gtk/Session.cc +++ b/gtk/Session.cc @@ -42,18 +42,21 @@ using namespace std::literals; namespace { -using TrVariantPtr = std::shared_ptr; - -TrVariantPtr create_variant(tr_variant&& other) +class TrVariantDeleter { - auto result = TrVariantPtr( - new tr_variant{}, - [](tr_variant* ptr) - { - tr_variantClear(ptr); - std::default_delete()(ptr); - }); - *result = std::move(other); +public: + void operator()(tr_variant* ptr) const + { + tr_variantClear(ptr); + std::default_delete()(ptr); + } +}; + +using TrVariantPtr = std::unique_ptr; + +TrVariantPtr create_variant(tr_variant& other) +{ + auto result = TrVariantPtr(new tr_variant(other)); tr_variantInitBool(&other, false); return result; } @@ -105,7 +108,7 @@ public: void add_torrent(tr_torrent* tor, bool do_notify); bool add_from_url(Glib::ustring const& url); - void send_rpc_request(tr_variant const* request, int64_t tag, std::function const& response_func); + void send_rpc_request(tr_variant const* request, int64_t tag, std::function const& response_func); void commit_prefs_change(tr_quark key); @@ -1556,17 +1559,17 @@ namespace int64_t nextTag = 1; -std::map> pendingRequests; +std::map> pendingRequests; -bool core_read_rpc_response_idle(TrVariantPtr const& response) +bool core_read_rpc_response_idle(tr_variant& response) { - if (int64_t tag = 0; tr_variantDictFindInt(response.get(), TR_KEY_tag, &tag)) + if (int64_t tag = 0; tr_variantDictFindInt(&response, TR_KEY_tag, &tag)) { if (auto const data_it = pendingRequests.find(tag); data_it != pendingRequests.end()) { if (auto const& response_func = data_it->second; response_func) { - response_func(response.get()); + response_func(response); } pendingRequests.erase(data_it); @@ -1582,8 +1585,8 @@ bool core_read_rpc_response_idle(TrVariantPtr const& response) void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, gpointer /*user_data*/) { - Glib::signal_idle().connect([response_copy = create_variant(std::move(*response))]() mutable - { return core_read_rpc_response_idle(response_copy); }); + Glib::signal_idle().connect([owned_response = std::shared_ptr(create_variant(*response))]() mutable + { return core_read_rpc_response_idle(*owned_response); }); } } // namespace @@ -1591,7 +1594,7 @@ void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, gpoin void Session::Impl::send_rpc_request( tr_variant const* request, int64_t tag, - std::function const& response_func) + std::function const& response_func) { if (session_ == nullptr) { @@ -1627,12 +1630,12 @@ void Session::port_test() impl_->send_rpc_request( &request, tag, - [this](auto* response) + [this](auto& response) { tr_variant* args = nullptr; bool is_open = false; - if (!tr_variantDictFindDict(response, TR_KEY_arguments, &args) || + if (!tr_variantDictFindDict(&response, TR_KEY_arguments, &args) || !tr_variantDictFindBool(args, TR_KEY_port_is_open, &is_open)) { is_open = false; @@ -1659,12 +1662,12 @@ void Session::blocklist_update() impl_->send_rpc_request( &request, tag, - [this](auto* response) + [this](auto& response) { tr_variant* args = nullptr; int64_t ruleCount = 0; - if (!tr_variantDictFindDict(response, TR_KEY_arguments, &args) || + if (!tr_variantDictFindDict(&response, TR_KEY_arguments, &args) || !tr_variantDictFindInt(args, TR_KEY_blocklist_size, &ruleCount)) { ruleCount = -1;