From 239478925f3a6a20dda7f0c3f4a317e8ae15a7f5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 Jan 2024 08:32:58 -0600 Subject: [PATCH] fix: performance-enum-size warnings (#6504) --- gtk/FileList.cc | 2 +- gtk/FilterBar.cc | 37 +++++++++++++------------ gtk/FilterBase.h | 4 ++- gtk/ListModelAdapter.h | 3 +- gtk/Session.h | 3 +- gtk/SorterBase.h | 2 +- gtk/Torrent.h | 3 +- gtk/TorrentFilter.h | 6 ++-- gtk/Utils.h | 3 +- libtransmission/announcer-udp.cc | 4 +-- libtransmission/peer-msgs.cc | 4 +-- libtransmission/port-forwarding-upnp.cc | 5 ++-- libtransmission/rpc-server.cc | 3 +- libtransmission/rpcimpl.cc | 2 +- libtransmission/torrent-metainfo.cc | 2 +- libtransmission/tr-dht.cc | 2 +- tests/libtransmission/watchdir-test.cc | 3 +- 17 files changed, 50 insertions(+), 38 deletions(-) diff --git a/gtk/FileList.cc b/gtk/FileList.cc index 5704f98d0..4e98f4770 100644 --- a/gtk/FileList.cc +++ b/gtk/FileList.cc @@ -49,7 +49,7 @@ using namespace std::literals; namespace { -enum +enum : uint16_t { /* these two fields could be any number at all so long as they're not * TR_PRI_LOW, TR_PRI_NORMAL, TR_PRI_HIGH, true, or false */ diff --git a/gtk/FilterBar.cc b/gtk/FilterBar.cc index 38f720087..b5a3ac6d9 100644 --- a/gtk/FilterBar.cc +++ b/gtk/FilterBar.cc @@ -45,13 +45,19 @@ #include #include +namespace +{ +using ActivityType = TorrentFilter::Activity; +using TrackerType = TorrentFilter::Tracker; + +constexpr auto ActivitySeparator = static_cast(-1); +constexpr auto TrackerSeparator = static_cast(-1); +} // namespace + class FilterBar::Impl { using FilterModel = IF_GTKMM4(Gtk::FilterListModel, Gtk::TreeModelFilter); - using TrackerType = TorrentFilter::Tracker; - using ActivityType = TorrentFilter::Activity; - public: Impl(FilterBar& widget, Glib::RefPtr const& core); ~Impl(); @@ -118,15 +124,10 @@ private: sigc::connection update_filter_models_on_change_tag_; }; -/*** -**** -**** TRACKERS -**** -***/ +// --- TRACKERS namespace { - class TrackerFilterModelColumns : public Gtk::TreeModelColumnRecord { public: @@ -141,7 +142,7 @@ public: Gtk::TreeModelColumn displayname; /* human-readable name; ie, Legaltorrents */ Gtk::TreeModelColumn count; /* how many matches there are */ - Gtk::TreeModelColumn type; + Gtk::TreeModelColumn type; Gtk::TreeModelColumn sitename; // pattern-matching text; see tr_parsed_url.sitename Gtk::TreeModelColumn> pixbuf; }; @@ -298,7 +299,7 @@ bool FilterBar::Impl::tracker_filter_model_update() add->set_value(tracker_filter_cols.sitename, Glib::ustring{ site.sitename }); add->set_value(tracker_filter_cols.displayname, get_name_from_host(site.sitename)); add->set_value(tracker_filter_cols.count, site.count); - add->set_value(tracker_filter_cols.type, static_cast(TrackerType::HOST)); + add->set_value(tracker_filter_cols.type, TrackerType::HOST); auto path = tracker_model_->get_path(add); core_->favicon_cache().load( site.announce_url, @@ -322,17 +323,17 @@ Glib::RefPtr FilterBar::Impl::tracker_filter_model_new() auto iter = store->append(); iter->set_value(tracker_filter_cols.displayname, Glib::ustring(_("All"))); - iter->set_value(tracker_filter_cols.type, static_cast(TrackerType::ALL)); + iter->set_value(tracker_filter_cols.type, TrackerType::ALL); iter = store->append(); - iter->set_value(tracker_filter_cols.type, -1); + iter->set_value(tracker_filter_cols.type, TrackerSeparator); return store; } bool FilterBar::Impl::is_it_a_separator(Gtk::TreeModel::const_iterator const& iter) { - return iter->get_value(tracker_filter_cols.type) == -1; + return iter->get_value(tracker_filter_cols.type) == TrackerSeparator; } void FilterBar::Impl::render_pixbuf_func(Gtk::CellRendererPixbuf& cell_renderer, Gtk::TreeModel::const_iterator const& iter) @@ -406,7 +407,7 @@ public: Gtk::TreeModelColumn name; Gtk::TreeModelColumn count; - Gtk::TreeModelColumn type; + Gtk::TreeModelColumn type; Gtk::TreeModelColumn icon_name; }; @@ -416,7 +417,7 @@ ActivityFilterModelColumns const activity_filter_cols; bool FilterBar::Impl::activity_is_it_a_separator(Gtk::TreeModel::const_iterator const& iter) { - return iter->get_value(activity_filter_cols.type) == -1; + return iter->get_value(activity_filter_cols.type) == ActivitySeparator; } void FilterBar::Impl::status_model_update_count(Gtk::TreeModel::iterator const& iter, int n) @@ -434,7 +435,7 @@ bool FilterBar::Impl::activity_filter_model_update() for (auto& row : activity_model_->children()) { auto const type = row.get_value(activity_filter_cols.type); - if (type == -1) + if (type == ActivitySeparator) { continue; } @@ -487,7 +488,7 @@ Glib::RefPtr FilterBar::Impl::activity_filter_model_new() Glib::ustring(); auto const iter = store->append(); iter->set_value(activity_filter_cols.name, name); - iter->set_value(activity_filter_cols.type, static_cast(type.type)); + iter->set_value(activity_filter_cols.type, type.type); iter->set_value(activity_filter_cols.icon_name, Glib::ustring(type.icon_name != nullptr ? type.icon_name : "")); } diff --git a/gtk/FilterBase.h b/gtk/FilterBase.h index 2cf726661..866a8194c 100644 --- a/gtk/FilterBase.h +++ b/gtk/FilterBase.h @@ -15,12 +15,14 @@ #include #endif +#include + template class FilterBase : public IF_GTKMM4(Gtk::Filter, Glib::Object) { public: #if !GTKMM_CHECK_VERSION(4, 0, 0) - enum class Change{ + enum class Change : uint8_t{ DIFFERENT, LESS_STRICT, MORE_STRICT, diff --git a/gtk/ListModelAdapter.h b/gtk/ListModelAdapter.h index 859322814..1c569248f 100644 --- a/gtk/ListModelAdapter.h +++ b/gtk/ListModelAdapter.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -25,7 +26,7 @@ class ListModelAdapter using IdGetter = std::function const&)>; using ValueGetter = std::function const&, int, Glib::ValueBase&)>; - enum class PositionAdjustment + enum class PositionAdjustment : int8_t { DECREMENT = -1, INCREMENT = 1, diff --git a/gtk/Session.h b/gtk/Session.h index 34732a983..e4799f8bf 100644 --- a/gtk/Session.h +++ b/gtk/Session.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ class Session : public Glib::Object { public: - enum ErrorCode + enum ErrorCode : uint16_t { ERR_ADD_TORRENT_ERR = 1, ERR_ADD_TORRENT_DUP = 2, diff --git a/gtk/SorterBase.h b/gtk/SorterBase.h index 957994686..e487d3beb 100644 --- a/gtk/SorterBase.h +++ b/gtk/SorterBase.h @@ -20,7 +20,7 @@ class SorterBase : public IF_GTKMM4(Gtk::Sorter, Glib::Object) { public: #if !GTKMM_CHECK_VERSION(4, 0, 0) - enum class Change{ + enum class Change : uint8_t{ DIFFERENT, INVERTED, LESS_STRICT, diff --git a/gtk/Torrent.h b/gtk/Torrent.h index 17c04de16..c289e575c 100644 --- a/gtk/Torrent.h +++ b/gtk/Torrent.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -38,7 +39,7 @@ public: Gtk::TreeModelColumn name_collated; }; - enum class ChangeFlag + enum class ChangeFlag : uint8_t { ACTIVE_PEER_COUNT, ACTIVE_PEERS_DOWN, diff --git a/gtk/TorrentFilter.h b/gtk/TorrentFilter.h index 3795d7af0..6f36e07b4 100644 --- a/gtk/TorrentFilter.h +++ b/gtk/TorrentFilter.h @@ -11,10 +11,12 @@ #include #include +#include + class TorrentFilter : public FilterBase { public: - enum class Activity + enum class Activity : int8_t { ALL, DOWNLOADING, @@ -26,7 +28,7 @@ public: ERROR, }; - enum class Tracker + enum class Tracker : int8_t { ALL, HOST, diff --git a/gtk/Utils.h b/gtk/Utils.h index 980d1218f..ec35ed256 100644 --- a/gtk/Utils.h +++ b/gtk/Utils.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,7 @@ void gtr_error(std::string const& message); **** ***/ -enum class GtrUnicode +enum class GtrUnicode : uint8_t { Up, Down, diff --git a/libtransmission/announcer-udp.cc b/libtransmission/announcer-udp.cc index 5a69b18b1..799b05b51 100644 --- a/libtransmission/announcer-udp.cc +++ b/libtransmission/announcer-udp.cc @@ -70,7 +70,7 @@ auto tau_transaction_new() } // used in the "action" field of a request. Values defined in bep 15. -enum tau_action_t +enum tau_action_t : uint8_t { TAU_ACTION_CONNECT = 0, TAU_ACTION_ANNOUNCE = 1, @@ -254,7 +254,7 @@ struct tau_announce_request return created_at_ + TR_ANNOUNCE_TIMEOUT_SEC.count(); } - enum tau_announce_event + enum tau_announce_event : uint8_t { // Used in the "event" field of an announce request. // These values come from BEP 15 diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index e7cd9c028..233174908 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -150,7 +150,7 @@ auto constexpr Handshake = uint8_t{ 0 }; // Client-defined extension message IDs that we tell peers about // in the LTEP handshake and will respond to when sent in an LTEP // message. -enum LtepMessageIds +enum LtepMessageIds : uint8_t { // we support peer exchange (bep 11) // https://www.bittorrent.org/beps/bep_0011.html @@ -194,7 +194,7 @@ auto constexpr MaxPexPeerCount = size_t{ 50 }; // --- -enum class EncryptionPreference +enum class EncryptionPreference : uint8_t { Unknown, Yes, diff --git a/libtransmission/port-forwarding-upnp.cc b/libtransmission/port-forwarding-upnp.cc index a6eddd0df..46fc5eb0e 100644 --- a/libtransmission/port-forwarding-upnp.cc +++ b/libtransmission/port-forwarding-upnp.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,7 @@ namespace { -enum class UpnpState +enum class UpnpState : uint8_t { Idle, Failed, @@ -219,7 +220,7 @@ void tr_upnpDeletePortMapping(tr_upnp const* handle, char const* proto, tr_port UPNP_DeletePortMapping(handle->urls.controlURL, handle->data.first.servicetype, port_str.c_str(), proto, nullptr); } -enum +enum : uint8_t { UPNP_IGD_NONE = 0, UPNP_IGD_VALID_CONNECTED = 1, diff --git a/libtransmission/rpc-server.cc b/libtransmission/rpc-server.cc index 97f86fdab..f024c4c9f 100644 --- a/libtransmission/rpc-server.cc +++ b/libtransmission/rpc-server.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include /* for strcspn() */ #include #include @@ -77,7 +78,7 @@ auto inline constexpr TrUnixAddrStrLen = size_t{ sizeof(((struct sockaddr_un*)nu std::size(TrUnixSocketPrefix) }; #endif -enum tr_rpc_address_type +enum tr_rpc_address_type : uint8_t { TR_RPC_INET_ADDR, TR_RPC_UNIX_ADDR diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 75716dc05..155794c38 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -54,7 +54,7 @@ auto constexpr RpcVersion = int64_t{ 18 }; auto constexpr RpcVersionMin = int64_t{ 14 }; auto constexpr RpcVersionSemver = "5.4.0"sv; -enum class TrFormat +enum class TrFormat : uint8_t { Object, Table diff --git a/libtransmission/torrent-metainfo.cc b/libtransmission/torrent-metainfo.cc index 031e9bc88..4d43135ea 100644 --- a/libtransmission/torrent-metainfo.cc +++ b/libtransmission/torrent-metainfo.cc @@ -71,7 +71,7 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler; using Id = std::array; - enum class SwarmStatus + enum class SwarmStatus : uint8_t { Stopped, Broken, diff --git a/tests/libtransmission/watchdir-test.cc b/tests/libtransmission/watchdir-test.cc index 884c47473..a6b9775e6 100644 --- a/tests/libtransmission/watchdir-test.cc +++ b/tests/libtransmission/watchdir-test.cc @@ -4,6 +4,7 @@ // License text can be found in the licenses/ folder. #include +#include #include #include #include @@ -50,7 +51,7 @@ static_assert(ProcessEventsTimeout > GenericRescanInterval); namespace libtransmission::test { -enum class WatchMode +enum class WatchMode : uint8_t { NATIVE, GENERIC