mirror of
https://github.com/transmission/transmission
synced 2025-01-03 13:35:36 +00:00
Fix issues reported by clang-tidy performance
checks (GTK client) (#4160)
* Fix `performance-move-const-arg` clang-tidy issues * Fix `performance-no-automatic-move` clang-tidy issues * Extend clang-tidy configuration
This commit is contained in:
parent
b322971f6a
commit
fd9c454c45
5 changed files with 31 additions and 27 deletions
|
@ -7,6 +7,7 @@ Checks: >
|
||||||
-cppcoreguidelines-narrowing-conversions,
|
-cppcoreguidelines-narrowing-conversions,
|
||||||
modernize-*,
|
modernize-*,
|
||||||
-modernize-use-trailing-return-type,
|
-modernize-use-trailing-return-type,
|
||||||
|
performance-*,
|
||||||
readability-*,
|
readability-*,
|
||||||
-readability-function-cognitive-complexity,
|
-readability-function-cognitive-complexity,
|
||||||
-readability-identifier-length,
|
-readability-identifier-length,
|
||||||
|
|
|
@ -112,7 +112,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
|
||||||
{
|
{
|
||||||
myBuilder = builder.get();
|
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);
|
auto const match = gtr_pref_string_get(TR_KEY_sort_mode);
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,7 @@ bool tracker_filter_model_update(Glib::RefPtr<Gtk::TreeStore> const& tracker_mod
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::TreeStore> tracker_filter_model_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
Glib::RefPtr<Gtk::TreeStore> tracker_filter_model_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
||||||
{
|
{
|
||||||
auto const store = Gtk::TreeStore::create(tracker_filter_cols);
|
auto store = Gtk::TreeStore::create(tracker_filter_cols);
|
||||||
|
|
||||||
auto iter = store->append();
|
auto iter = store->append();
|
||||||
iter->set_value(tracker_filter_cols.displayname, Glib::ustring(_("All")));
|
iter->set_value(tracker_filter_cols.displayname, Glib::ustring(_("All")));
|
||||||
|
@ -531,7 +531,7 @@ Glib::RefPtr<Gtk::ListStore> activity_filter_model_new(Glib::RefPtr<Gtk::TreeMod
|
||||||
{ ACTIVITY_FILTER_ERROR, nullptr, N_("Error"), "dialog-error" },
|
{ ACTIVITY_FILTER_ERROR, nullptr, N_("Error"), "dialog-error" },
|
||||||
} });
|
} });
|
||||||
|
|
||||||
auto const store = Gtk::ListStore::create(activity_filter_cols);
|
auto store = Gtk::ListStore::create(activity_filter_cols);
|
||||||
|
|
||||||
for (auto const& type : types)
|
for (auto const& type : types)
|
||||||
{
|
{
|
||||||
|
|
|
@ -686,7 +686,7 @@ RemotePage::WhitelistModelColumns const RemotePage::whitelist_cols;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::ListStore> RemotePage::whitelist_tree_model_new(std::string const& whitelist)
|
Glib::RefPtr<Gtk::ListStore> 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::istringstream stream(whitelist);
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
|
@ -42,18 +42,21 @@ using namespace std::literals;
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
using TrVariantPtr = std::shared_ptr<tr_variant>;
|
class TrVariantDeleter
|
||||||
|
|
||||||
TrVariantPtr create_variant(tr_variant&& other)
|
|
||||||
{
|
{
|
||||||
auto result = TrVariantPtr(
|
public:
|
||||||
new tr_variant{},
|
void operator()(tr_variant* ptr) const
|
||||||
[](tr_variant* ptr)
|
{
|
||||||
{
|
tr_variantClear(ptr);
|
||||||
tr_variantClear(ptr);
|
std::default_delete<tr_variant>()(ptr);
|
||||||
std::default_delete<tr_variant>()(ptr);
|
}
|
||||||
});
|
};
|
||||||
*result = std::move(other);
|
|
||||||
|
using TrVariantPtr = std::unique_ptr<tr_variant, TrVariantDeleter>;
|
||||||
|
|
||||||
|
TrVariantPtr create_variant(tr_variant& other)
|
||||||
|
{
|
||||||
|
auto result = TrVariantPtr(new tr_variant(other));
|
||||||
tr_variantInitBool(&other, false);
|
tr_variantInitBool(&other, false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +108,7 @@ public:
|
||||||
void add_torrent(tr_torrent* tor, bool do_notify);
|
void add_torrent(tr_torrent* tor, bool do_notify);
|
||||||
bool add_from_url(Glib::ustring const& url);
|
bool add_from_url(Glib::ustring const& url);
|
||||||
|
|
||||||
void send_rpc_request(tr_variant const* request, int64_t tag, std::function<void(tr_variant*)> const& response_func);
|
void send_rpc_request(tr_variant const* request, int64_t tag, std::function<void(tr_variant&)> const& response_func);
|
||||||
|
|
||||||
void commit_prefs_change(tr_quark key);
|
void commit_prefs_change(tr_quark key);
|
||||||
|
|
||||||
|
@ -1556,17 +1559,17 @@ namespace
|
||||||
|
|
||||||
int64_t nextTag = 1;
|
int64_t nextTag = 1;
|
||||||
|
|
||||||
std::map<int64_t, std::function<void(tr_variant*)>> pendingRequests;
|
std::map<int64_t, std::function<void(tr_variant&)>> 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 data_it = pendingRequests.find(tag); data_it != pendingRequests.end())
|
||||||
{
|
{
|
||||||
if (auto const& response_func = data_it->second; response_func)
|
if (auto const& response_func = data_it->second; response_func)
|
||||||
{
|
{
|
||||||
response_func(response.get());
|
response_func(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingRequests.erase(data_it);
|
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*/)
|
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
|
Glib::signal_idle().connect([owned_response = std::shared_ptr(create_variant(*response))]() mutable
|
||||||
{ return core_read_rpc_response_idle(response_copy); });
|
{ return core_read_rpc_response_idle(*owned_response); });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -1591,7 +1594,7 @@ void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, gpoin
|
||||||
void Session::Impl::send_rpc_request(
|
void Session::Impl::send_rpc_request(
|
||||||
tr_variant const* request,
|
tr_variant const* request,
|
||||||
int64_t tag,
|
int64_t tag,
|
||||||
std::function<void(tr_variant*)> const& response_func)
|
std::function<void(tr_variant&)> const& response_func)
|
||||||
{
|
{
|
||||||
if (session_ == nullptr)
|
if (session_ == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -1627,12 +1630,12 @@ void Session::port_test()
|
||||||
impl_->send_rpc_request(
|
impl_->send_rpc_request(
|
||||||
&request,
|
&request,
|
||||||
tag,
|
tag,
|
||||||
[this](auto* response)
|
[this](auto& response)
|
||||||
{
|
{
|
||||||
tr_variant* args = nullptr;
|
tr_variant* args = nullptr;
|
||||||
bool is_open = false;
|
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))
|
!tr_variantDictFindBool(args, TR_KEY_port_is_open, &is_open))
|
||||||
{
|
{
|
||||||
is_open = false;
|
is_open = false;
|
||||||
|
@ -1659,12 +1662,12 @@ void Session::blocklist_update()
|
||||||
impl_->send_rpc_request(
|
impl_->send_rpc_request(
|
||||||
&request,
|
&request,
|
||||||
tag,
|
tag,
|
||||||
[this](auto* response)
|
[this](auto& response)
|
||||||
{
|
{
|
||||||
tr_variant* args = nullptr;
|
tr_variant* args = nullptr;
|
||||||
int64_t ruleCount = 0;
|
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))
|
!tr_variantDictFindInt(args, TR_KEY_blocklist_size, &ruleCount))
|
||||||
{
|
{
|
||||||
ruleCount = -1;
|
ruleCount = -1;
|
||||||
|
|
Loading…
Reference in a new issue