1
0
Fork 0
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:
Mike Gelfand 2022-11-13 21:50:07 +01:00 committed by GitHub
parent b322971f6a
commit fd9c454c45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 27 deletions

View file

@ -7,6 +7,7 @@ Checks: >
-cppcoreguidelines-narrowing-conversions,
modernize-*,
-modernize-use-trailing-return-type,
performance-*,
readability-*,
-readability-function-cognitive-complexity,
-readability-identifier-length,

View file

@ -112,7 +112,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
{
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);

View file

@ -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)
{
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<Gtk::ListStore> activity_filter_model_new(Glib::RefPtr<Gtk::TreeMod
{ 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)
{

View file

@ -686,7 +686,7 @@ RemotePage::WhitelistModelColumns const RemotePage::whitelist_cols;
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::string s;

View file

@ -42,18 +42,21 @@ using namespace std::literals;
namespace
{
using TrVariantPtr = std::shared_ptr<tr_variant>;
TrVariantPtr create_variant(tr_variant&& other)
class TrVariantDeleter
{
auto result = TrVariantPtr(
new tr_variant{},
[](tr_variant* ptr)
{
tr_variantClear(ptr);
std::default_delete<tr_variant>()(ptr);
});
*result = std::move(other);
public:
void operator()(tr_variant* ptr) const
{
tr_variantClear(ptr);
std::default_delete<tr_variant>()(ptr);
}
};
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);
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<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);
@ -1556,17 +1559,17 @@ namespace
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& 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<void(tr_variant*)> const& response_func)
std::function<void(tr_variant&)> 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;