From 42b09b22df22740a4cb838a2e4fb7a4556214a12 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 24 Dec 2023 11:02:54 -0600 Subject: [PATCH] refactor: reduce utils.h includes (#6431) --- libtransmission/announce-list.h | 2 +- libtransmission/announcer-common.h | 1 + libtransmission/favicon-cache.h | 2 +- libtransmission/file-piece-map.h | 1 - libtransmission/log.cc | 1 + libtransmission/magnet-metainfo.cc | 5 +++++ libtransmission/magnet-metainfo.h | 6 +----- libtransmission/makemeta.cc | 6 +++++- libtransmission/makemeta.h | 6 +----- libtransmission/net.h | 2 +- libtransmission/peer-io.h | 1 + libtransmission/torrent-ctor.h | 1 - libtransmission/tr-buffer.h | 8 +++++--- libtransmission/tr-macros.h | 4 ++-- libtransmission/utils.h | 17 ++++++++--------- libtransmission/values.h | 1 + libtransmission/verify.cc | 1 - 17 files changed, 34 insertions(+), 31 deletions(-) diff --git a/libtransmission/announce-list.h b/libtransmission/announce-list.h index ea1828c23..b93194994 100644 --- a/libtransmission/announce-list.h +++ b/libtransmission/announce-list.h @@ -14,7 +14,7 @@ #include "libtransmission/transmission.h" #include "libtransmission/interned-string.h" -#include "libtransmission/tr-macros.h" +#include "libtransmission/tr-macros.h" // TR_CONSTEXPR20 #include "libtransmission/variant.h" #include "libtransmission/web-utils.h" diff --git a/libtransmission/announcer-common.h b/libtransmission/announcer-common.h index b481d4eb4..caba49332 100644 --- a/libtransmission/announcer-common.h +++ b/libtransmission/announcer-common.h @@ -23,6 +23,7 @@ #include "libtransmission/interned-string.h" #include "libtransmission/net.h" #include "libtransmission/peer-mgr.h" // tr_pex +#include "libtransmission/tr-macros.h" // tr_peer_id_t struct tr_url_parsed_t; diff --git a/libtransmission/favicon-cache.h b/libtransmission/favicon-cache.h index 4f753d5fd..b0bf0a243 100644 --- a/libtransmission/favicon-cache.h +++ b/libtransmission/favicon-cache.h @@ -21,7 +21,7 @@ #include #include -#include +#include // for tr_file_save() #include #include diff --git a/libtransmission/file-piece-map.h b/libtransmission/file-piece-map.h index dcd1f259d..c8b5cf240 100644 --- a/libtransmission/file-piece-map.h +++ b/libtransmission/file-piece-map.h @@ -18,7 +18,6 @@ #include "libtransmission/bitfield.h" #include "libtransmission/tr-macros.h" // TR_CONSTEXPR20 -#include "libtransmission/utils.h" struct tr_block_info; struct tr_torrent_metainfo; diff --git a/libtransmission/log.cc b/libtransmission/log.cc index 776689bb4..62f53233b 100644 --- a/libtransmission/log.cc +++ b/libtransmission/log.cc @@ -10,6 +10,7 @@ #include // back_insert_iterator, empty #include #include +#include #include #include #include diff --git a/libtransmission/magnet-metainfo.cc b/libtransmission/magnet-metainfo.cc index 591af5767..3cb783aae 100644 --- a/libtransmission/magnet-metainfo.cc +++ b/libtransmission/magnet-metainfo.cc @@ -193,6 +193,11 @@ std::string tr_magnet_metainfo::magnet() const return std::string{ buf.sv() }; } +void tr_magnet_metainfo::set_name(std::string_view name) +{ + name_ = tr_strv_convert_utf8(name); +} + void tr_magnet_metainfo::add_webseed(std::string_view webseed) { if (!tr_urlIsValid(webseed)) diff --git a/libtransmission/magnet-metainfo.h b/libtransmission/magnet-metainfo.h index c7b1ec74a..09e238b7a 100644 --- a/libtransmission/magnet-metainfo.h +++ b/libtransmission/magnet-metainfo.h @@ -13,7 +13,6 @@ #include "libtransmission/announce-list.h" #include "libtransmission/crypto-utils.h" #include "libtransmission/tr-macros.h" // TR_CONSTEXPR20, tr_sha1_digest_t -#include "libtransmission/utils.h" // tr_strv_convert_utf8() struct tr_error; @@ -66,10 +65,7 @@ public: return info_hash2_str_; } - void set_name(std::string_view name) - { - name_ = tr_strv_convert_utf8(name); - } + void set_name(std::string_view name); void add_webseed(std::string_view webseed); diff --git a/libtransmission/makemeta.cc b/libtransmission/makemeta.cc index e2cb79b2b..9730af471 100644 --- a/libtransmission/makemeta.cc +++ b/libtransmission/makemeta.cc @@ -8,7 +8,6 @@ #include #include // time() #include -#include #include #include #include @@ -372,6 +371,11 @@ std::string tr_metainfo_builder::benc(tr_error* error) const return tr_variant_serde::benc().to_string(tr_variant{ std::move(top) }); } +bool tr_metainfo_builder::save(std::string_view filename, tr_error* error) const +{ + return tr_file_save(filename, benc(error), error); +} + uint32_t tr_metainfo_builder::default_piece_size(uint64_t total_size) noexcept { // Ideally, we want approximately 2^10 = 1024 pieces, give or take a few hundred pieces. diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index e69c9e758..b211eb8a9 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -21,7 +21,6 @@ #include "libtransmission/file.h" #include "libtransmission/torrent-files.h" #include "libtransmission/tr-macros.h" // TR_CONSTEXPR20 -#include "libtransmission/utils.h" // for tr_file_save() class tr_metainfo_builder { @@ -67,10 +66,7 @@ public: [[nodiscard]] std::string benc(tr_error* error = nullptr) const; // generate the metainfo and save it to a torrent file - bool save(std::string_view filename, tr_error* error = nullptr) const - { - return tr_file_save(filename, benc(error), error); - } + bool save(std::string_view filename, tr_error* error = nullptr) const; /// setters diff --git a/libtransmission/net.h b/libtransmission/net.h index ad9066721..fc23685f4 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -61,7 +61,7 @@ using tr_socket_t = int; #endif #include "libtransmission/tr-assert.h" -#include "libtransmission/utils.h" +#include "libtransmission/utils.h" // for tr_compare_3way() /** * Literally just a port number. diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index b338551bd..647deb23f 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -14,6 +14,7 @@ #include // uintX_t #include #include +#include #include // std::pair #include // for evutil_socket_t diff --git a/libtransmission/torrent-ctor.h b/libtransmission/torrent-ctor.h index f15e5dff0..d06bdd590 100644 --- a/libtransmission/torrent-ctor.h +++ b/libtransmission/torrent-ctor.h @@ -20,7 +20,6 @@ #include "libtransmission/torrent-metainfo.h" #include "libtransmission/torrent.h" -#include "libtransmission/tr-assert.h" #include "libtransmission/tr-macros.h" struct tr_error; diff --git a/libtransmission/tr-buffer.h b/libtransmission/tr-buffer.h index f01f48a2f..10206f607 100644 --- a/libtransmission/tr-buffer.h +++ b/libtransmission/tr-buffer.h @@ -6,9 +6,9 @@ #pragma once #include // for std::copy_n -#include -#include -#include +#include // size_t +#include // std::allocator +#include #include #include @@ -16,6 +16,8 @@ #include "libtransmission/error.h" #include "libtransmission/net.h" // tr_socket_t +#include "libtransmission/tr-assert.h" +#include "libtransmission/tr-macros.h" // TR_CONSTEXPR #include "libtransmission/utils.h" // for tr_htonll(), tr_ntohll() namespace libtransmission diff --git a/libtransmission/tr-macros.h b/libtransmission/tr-macros.h index 19acc9ca4..fd17a01e4 100644 --- a/libtransmission/tr-macros.h +++ b/libtransmission/tr-macros.h @@ -6,8 +6,8 @@ #pragma once #include -#include // size_t -#include // uint32_t +#include // for std::byte +#include // for uint32_t // --- diff --git a/libtransmission/utils.h b/libtransmission/utils.h index a4c76c641..f374da76f 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -5,9 +5,10 @@ #pragma once +#include // for std::for_each() #include -#include // uint8_t, uint32_t, uint64_t #include // size_t +#include // uint8_t, uint32_t, uint64_t #include // time_t #include #include @@ -17,10 +18,6 @@ #include #include -#include "libtransmission/tr-macros.h" -#include "libtransmission/variant.h" -#include "libtransmission/values.h" - struct tr_error; /** @@ -310,15 +307,17 @@ constexpr void tr_timeUpdate(time_t now) noexcept class tr_net_init_mgr { -private: - tr_net_init_mgr(); - TR_DISABLE_COPY_MOVE(tr_net_init_mgr) - public: ~tr_net_init_mgr(); static std::unique_ptr create(); private: + tr_net_init_mgr(); + tr_net_init_mgr(tr_net_init_mgr&&) = delete; + tr_net_init_mgr(tr_net_init_mgr const&) = delete; + tr_net_init_mgr& operator=(tr_net_init_mgr&&) = delete; + tr_net_init_mgr& operator=(tr_net_init_mgr const&) = delete; + static bool initialised; }; diff --git a/libtransmission/values.h b/libtransmission/values.h index b01968f80..c3771e443 100644 --- a/libtransmission/values.h +++ b/libtransmission/values.h @@ -6,6 +6,7 @@ #pragma once #include +#include // size_t #include // for std::fabs(), std::floor() #include // for uint64_t #include diff --git a/libtransmission/verify.cc b/libtransmission/verify.cc index 466fc4975..78bb921c5 100644 --- a/libtransmission/verify.cc +++ b/libtransmission/verify.cc @@ -10,7 +10,6 @@ #include // uint64_t, uint32_t #include #include -#include #include #include // for std::move() #include