refactor: remove unused functions (#2863)

* refactor: annotate nodiscard, constexpr, noexcept methods

* refactor: remove unused tr_blocklistFileExists()

* refactor: remove unused tr_blocklistFileIsEnabled()

* refactor: remove unused tr_ctorGetContents

* refactor: remove unused tr_error_is_set()

* refactor: remove unused tr_handshakeGetAddr()

* refactor: remove unused tr_ctorSetLabels()

* refactor: remove unused tr_http_escape_sha1()

* refactor: remove unused tr_lpdEnabled()

* refactor: remove unused tr_ptrArrayPop()

* refactor: remove unused tr_torrentClearIdleLimitHitCallback()

* refactor: remove unused tr_torrentFindFromHash()

* refactor: remove unused tr_sha1_to_string()

* refactor: remove unused tr_torrents::get()

* refactor: remove unused tr_isEncryptionMode()

* refactor: remove unused tr_isPreallocationMode()

* refactor: remove unused tr_ptrArrayBack()

* refactor: remove unused tr_ptrArrayClear()

* refactor: remove unused tr_torrents::get()

* refactor: remove unused Session::torrentSet()

* refactor: remove unused peer_atom comparison operators

* refactor: remove unused peer_atom::compare()

* refactor: remove unused Qt variantInit(tr_variant*, unsigned)
This commit is contained in:
Charles Kerr 2022-04-01 21:55:30 -05:00 committed by GitHub
parent ca5799a4a8
commit 46cc95f72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1 additions and 205 deletions

View File

@ -163,11 +163,6 @@ void tr_blocklistFileFree(tr_blocklistFile* b)
tr_free(b);
}
bool tr_blocklistFileExists(tr_blocklistFile const* b)
{
return tr_sys_path_exists(b->filename);
}
int tr_blocklistFileGetRuleCount(tr_blocklistFile const* b)
{
blocklistEnsureLoaded((tr_blocklistFile*)b);
@ -175,11 +170,6 @@ int tr_blocklistFileGetRuleCount(tr_blocklistFile const* b)
return b->ruleCount;
}
bool tr_blocklistFileIsEnabled(tr_blocklistFile* b)
{
return b->isEnabled;
}
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled)
{
TR_ASSERT(b != nullptr);

View File

@ -14,16 +14,12 @@ struct tr_blocklistFile;
tr_blocklistFile* tr_blocklistFileNew(char const* filename, bool isEnabled);
bool tr_blocklistFileExists(tr_blocklistFile const* b);
char const* tr_blocklistFileGetFilename(tr_blocklistFile const* b);
int tr_blocklistFileGetRuleCount(tr_blocklistFile const* b);
void tr_blocklistFileFree(tr_blocklistFile* b);
bool tr_blocklistFileIsEnabled(tr_blocklistFile* b);
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled);
bool tr_blocklistFileHasAddress(tr_blocklistFile* b, struct tr_address const* addr);

View File

@ -203,12 +203,6 @@ std::string tr_sha1_to_string(tr_sha1_digest_t const& digest)
return str;
}
char* tr_sha1_to_string(tr_sha1_digest_t const& digest, char* strbuf)
{
tr_binary_to_hex(std::data(digest), strbuf, std::size(digest));
return strbuf + (std::size(digest) * 2);
}
static void tr_hex_to_binary(char const* input, void* voutput, size_t byte_length)
{
static char constexpr Hex[] = "0123456789abcdef";

View File

@ -180,12 +180,6 @@ std::string tr_base64_encode(std::string_view input);
*/
std::string tr_base64_decode(std::string_view input);
/**
* @brief Generate an ascii hex string for a sha1 digest.
* @return address pointing past the last element written.
*/
char* tr_sha1_to_string(tr_sha1_digest_t const& digest, char* strbuf);
/**
* @brief Generate an ascii hex string for a sha1 digest.
*/

View File

@ -14,11 +14,6 @@
#include "tr-macros.h"
#include "utils.h"
bool tr_error_is_set(tr_error const* const* error)
{
return (error != nullptr) && (*error != nullptr);
}
void tr_error_free(tr_error* error)
{
if (error == nullptr)

View File

@ -23,8 +23,6 @@ struct tr_error
char* message;
};
bool tr_error_is_set(tr_error const* const* error);
/**
* @brief Free memory used by error object.
*

View File

@ -1237,11 +1237,3 @@ tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake)
handshake->io = nullptr;
return io;
}
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port)
{
TR_ASSERT(handshake != nullptr);
TR_ASSERT(handshake->io != nullptr);
return tr_peerIoGetAddress(handshake->io, port);
}

View File

@ -43,8 +43,6 @@ tr_handshake* tr_handshakeNew(
tr_handshake_done_func when_done,
void* when_done_user_data);
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port);
void tr_handshakeAbort(tr_handshake* handshake);
tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake);

View File

@ -128,26 +128,6 @@ struct peer_atom
time_t shelf_date;
tr_peer* peer; /* will be nullptr if not connected */
tr_address addr;
[[nodiscard]] int compare(peer_atom const& that) const
{
return addr.compare(that.addr);
}
[[nodiscard]] bool operator==(peer_atom const& that) const
{
return compare(that) == 0;
}
[[nodiscard]] bool operator<(peer_atom const& that) const
{
return compare(that) < 0;
}
[[nodiscard]] bool operator>(peer_atom const& that) const
{
return compare(that) > 0;
}
};
#ifndef TR_ENABLE_ASSERTS

View File

@ -104,18 +104,6 @@ int tr_ptrArrayInsert(tr_ptrArray* t, void* ptr, int pos)
return pos;
}
void* tr_ptrArrayPop(tr_ptrArray* t)
{
void* ret = nullptr;
if (t->n_items != 0)
{
ret = t->items[--t->n_items];
}
return ret;
}
void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end)
{
if (end < 0)

View File

@ -46,19 +46,6 @@ void tr_ptrArrayForeach(tr_ptrArray* array, PtrArrayForeachFunc func);
@return the nth item in a tr_ptrArray */
void* tr_ptrArrayNth(tr_ptrArray* array, int i);
/** @brief Remove the last item from the array and return it
@return the pointer that's been removed from the array
@see tr_ptrArrayBack() */
void* tr_ptrArrayPop(tr_ptrArray* array);
/** @brief Return the last item in a tr_ptrArray
@return the last item in a tr_ptrArray, or nullptr if the array is empty
@see tr_ptrArrayPop() */
constexpr void* tr_ptrArrayBack(tr_ptrArray* array)
{
return array->n_items > 0 ? tr_ptrArrayNth(array, array->n_items - 1) : nullptr;
}
void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end);
static inline void tr_ptrArrayRemove(tr_ptrArray* t, int pos)
@ -69,11 +56,6 @@ static inline void tr_ptrArrayRemove(tr_ptrArray* t, int pos)
/** @brief Peek at the array pointer and its size, for easy iteration */
void** tr_ptrArrayPeek(tr_ptrArray* array, int* size);
constexpr void tr_ptrArrayClear(tr_ptrArray* a)
{
a->n_items = 0;
}
/** @brief Insert a pointer into the array at the specified position
@return the index of the stored pointer */
int tr_ptrArrayInsert(tr_ptrArray* array, void* insertMe, int pos);

View File

@ -458,16 +458,6 @@ constexpr bool tr_isSession(tr_session const* session)
return session != nullptr && session->magicNumber == SESSION_MAGIC_NUMBER;
}
constexpr bool tr_isPreallocationMode(tr_preallocation_mode m)
{
return m == TR_PREALLOCATE_NONE || m == TR_PREALLOCATE_SPARSE || m == TR_PREALLOCATE_FULL;
}
constexpr bool tr_isEncryptionMode(tr_encryption_mode m)
{
return m == TR_CLEAR_PREFERRED || m == TR_ENCRYPTION_PREFERRED || m == TR_ENCRYPTION_REQUIRED;
}
constexpr bool tr_isPriority(tr_priority_t p)
{
return p == TR_PRI_LOW || p == TR_PRI_NORMAL || p == TR_PRI_HIGH;

View File

@ -104,11 +104,6 @@ bool tr_ctorSetMetainfoFromMagnetLink(tr_ctor* ctor, char const* magnet_link, tr
return ctor->metainfo.parseMagnet(magnet_link != nullptr ? magnet_link : "", error);
}
std::string_view tr_ctorGetContents(tr_ctor const* ctor)
{
return std::string_view{ std::data(ctor->contents), std::size(ctor->contents) };
}
char const* tr_ctorGetSourceFile(tr_ctor const* ctor)
{
return ctor->torrent_filename.c_str();
@ -334,17 +329,6 @@ tr_priority_t tr_ctorGetBandwidthPriority(tr_ctor const* ctor)
****
***/
void tr_ctorSetLabels(tr_ctor* ctor, char const** labels, size_t len)
{
auto labels_set = tr_labels_t{};
for (size_t i = 0; i < len; i++)
{
labels_set.emplace(labels[i]);
}
tr_ctorSetLabels(ctor, std::move(labels_set));
}
void tr_ctorSetLabels(tr_ctor* ctor, tr_labels_t&& labels)
{
ctor->labels = std::move(labels);

View File

@ -85,11 +85,6 @@ tr_torrent* tr_torrentFindFromId(tr_session* session, int id)
return session->torrents().get(id);
}
tr_torrent* tr_torrentFindFromHash(tr_session* session, tr_sha1_digest_t const* hash)
{
return hash == nullptr ? nullptr : session->torrents().get(*hash);
}
tr_torrent* tr_torrentFindFromMetainfo(tr_session* session, tr_torrent_metainfo const* metainfo)
{
if (session == nullptr || metainfo == nullptr)
@ -1718,11 +1713,6 @@ void tr_torrentSetRatioLimitHitCallback(tr_torrent* tor, tr_torrent_ratio_limit_
tor->ratio_limit_hit_func_user_data = user_data;
}
void tr_torrentClearRatioLimitHitCallback(tr_torrent* torrent)
{
tr_torrentSetRatioLimitHitCallback(torrent, nullptr, nullptr);
}
void tr_torrentSetIdleLimitHitCallback(tr_torrent* tor, tr_torrent_idle_limit_hit_func func, void* user_data)
{
TR_ASSERT(tr_isTorrent(tor));
@ -1731,11 +1721,6 @@ void tr_torrentSetIdleLimitHitCallback(tr_torrent* tor, tr_torrent_idle_limit_hi
tor->idle_limit_hit_func_user_data = user_data;
}
void tr_torrentClearIdleLimitHitCallback(tr_torrent* torrent)
{
tr_torrentSetIdleLimitHitCallback(torrent, nullptr, nullptr);
}
static std::string buildLabelsString(tr_torrent const* tor)
{
auto buf = std::stringstream{};

View File

@ -55,8 +55,6 @@ void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor);
bool tr_ctorSaveContents(tr_ctor const* ctor, std::string_view filename, tr_error** error);
std::string_view tr_ctorGetContents(tr_ctor const* ctor);
tr_session* tr_ctorGetSession(tr_ctor const* ctor);
bool tr_ctorGetIncompleteDir(tr_ctor const* ctor, char const** setmeIncompleteDir);

View File

@ -42,21 +42,6 @@ struct CompareTorrentByHash
} // namespace
tr_torrent const* tr_torrents::get(int id) const
{
TR_ASSERT(0 < id);
TR_ASSERT(static_cast<size_t>(id) < std::size(by_id_));
if (static_cast<size_t>(id) >= std::size(by_id_))
{
return nullptr;
}
auto const* tor = by_id_.at(id);
TR_ASSERT(tor == nullptr || tor->uniqueId == id);
TR_ASSERT(removed_.count(id) == (tor == nullptr ? 1 : 0));
return tor;
}
tr_torrent* tr_torrents::get(int id)
{
TR_ASSERT(0 < id);
@ -72,12 +57,6 @@ tr_torrent* tr_torrents::get(int id)
return tor;
}
tr_torrent const* tr_torrents::get(std::string_view magnet_link) const
{
auto magnet = tr_magnet_metainfo{};
return magnet.parseMagnet(magnet_link) ? get(magnet.infoHash()) : nullptr;
}
tr_torrent* tr_torrents::get(std::string_view magnet_link)
{
auto magnet = tr_magnet_metainfo{};

View File

@ -33,7 +33,6 @@ public:
// O(1)
[[nodiscard]] tr_torrent* get(int id);
[[nodiscard]] tr_torrent const* get(int id) const;
// O(log n)
[[nodiscard]] tr_torrent const* get(tr_sha1_digest_t const& hash) const;
@ -52,7 +51,6 @@ public:
// These convenience functions use get(tr_sha1_digest_t const&)
// after parsing the magnet link to get the info hash. If you have
// the info hash already, use get() instead to avoid excess parsing.
[[nodiscard]] tr_torrent const* get(std::string_view magnet_link) const;
[[nodiscard]] tr_torrent* get(std::string_view magnet_link);
template<typename T>

View File

@ -32,7 +32,7 @@ using in_port_t = uint16_t; /* all missing */
#include "net.h"
#include "peer-mgr.h" /* tr_peerMgrAddPex() */
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
#include "torrent.h"
#include "tr-assert.h"
#include "tr-lpd.h"
#include "utils.h"
@ -417,11 +417,6 @@ void tr_lpdUninit(tr_session* ss)
session = nullptr;
}
bool tr_lpdEnabled(tr_session const* ss)
{
return ss != nullptr && ss == session;
}
/**
* @endcond */

View File

@ -10,7 +10,6 @@
int tr_lpdInit(tr_session*, tr_address*);
void tr_lpdUninit(tr_session*);
bool tr_lpdEnabled(tr_session const*);
bool tr_lpdSendAnnounce(tr_torrent const*);
/**

View File

@ -846,10 +846,6 @@ void tr_ctorSetFilePriorities(tr_ctor* ctor, tr_file_index_t const* files, tr_fi
/** @brief Set the download flag for files in a torrent */
void tr_ctorSetFilesWanted(tr_ctor* ctor, tr_file_index_t const* fileIndices, tr_file_index_t fileCount, bool wanted);
/** @brief Set labels for this torrent, the length of the labels array
must be the same size as len. */
void tr_ctorSetLabels(tr_ctor* ctor, char const** labels, size_t len);
/** @brief Get this peer constructor's peer limit */
bool tr_ctorGetPeerLimit(tr_ctor const* ctor, tr_ctorMode mode, uint16_t* setmeCount);
@ -997,9 +993,6 @@ tr_torrent* tr_torrentFindFromId(tr_session* session, int id);
tr_torrent* tr_torrentFindFromMetainfo(tr_session*, tr_torrent_metainfo const*);
tr_torrent* tr_torrentFindFromHash(tr_session* session, tr_sha1_digest_t const* hash);
/** @brief Convenience function similar to tr_torrentFindFromHash() */
tr_torrent* tr_torrentFindFromMagnetLink(tr_session* session, char const* link);
/**
@ -1223,8 +1216,6 @@ void tr_torrentSetMetadataCallback(tr_torrent* tor, tr_torrent_metadata_func fun
*/
void tr_torrentSetRatioLimitHitCallback(tr_torrent* torrent, tr_torrent_ratio_limit_hit_func func, void* user_data);
void tr_torrentClearRatioLimitHitCallback(tr_torrent* torrent);
/**
* Register to be notified whenever a torrent's idle limit
* has been hit. This will be called when the seeding torrent's
@ -1234,8 +1225,6 @@ void tr_torrentClearRatioLimitHitCallback(tr_torrent* torrent);
*/
void tr_torrentSetIdleLimitHitCallback(tr_torrent* torrent, tr_torrent_idle_limit_hit_func func, void* user_data);
void tr_torrentClearIdleLimitHitCallback(tr_torrent* torrent);
/**
* MANUAL ANNOUNCE
*

View File

@ -192,13 +192,6 @@ void tr_http_escape_sha1(char* out, tr_sha1_digest_t const& digest)
*out = '\0';
}
void tr_http_escape_sha1(char* out, uint8_t const* sha1_digest)
{
auto digest = tr_sha1_digest_t{};
std::copy_n(reinterpret_cast<std::byte const*>(sha1_digest), std::size(digest), std::begin(digest));
tr_http_escape_sha1(out, digest);
}
//// URLs
namespace

View File

@ -112,8 +112,6 @@ void tr_http_escape(OutputIt out, std::string_view in, bool escape_reserved)
}
}
void tr_http_escape_sha1(char* out, uint8_t const* sha1_digest);
void tr_http_escape_sha1(char* out, tr_sha1_digest_t const& digest);
char const* tr_webGetResponseStr(long response_code);

View File

@ -40,7 +40,6 @@
using ::trqt::variant_helpers::dictAdd;
using ::trqt::variant_helpers::dictFind;
using ::trqt::variant_helpers::getValue;
using ::trqt::variant_helpers::listAdd;
/***
****
@ -464,17 +463,6 @@ Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, Q
return torrentSetImpl(&args);
}
Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QPair<int, QString> const& value)
{
tr_variant args;
tr_variantInitDict(&args, 2);
addOptionalIds(&args, ids);
tr_variant* list(tr_variantDictAddList(&args, key, 2));
listAdd(list, value.first);
listAdd(list, value.second);
return torrentSetImpl(&args);
}
void Session::torrentSetLocation(torrent_ids_t const& ids, QString const& location, bool do_move)
{
tr_variant args;

View File

@ -89,7 +89,6 @@ public:
Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QString const& val);
Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QList<int> const& val);
Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QStringList const& val);
Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QPair<int, QString> const& val);
void torrentSetLocation(torrent_ids_t const& ids, QString const& path, bool do_move);
void torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname);

View File

@ -202,11 +202,6 @@ void variantInit(tr_variant* init_me, int value)
tr_variantInitInt(init_me, value);
}
void variantInit(tr_variant* init_me, unsigned int value)
{
tr_variantInitInt(init_me, value);
}
void variantInit(tr_variant* init_me, double value)
{
tr_variantInitReal(init_me, value);

View File

@ -193,7 +193,6 @@ auto dictFind(tr_variant* dict, tr_quark key)
void variantInit(tr_variant* init_me, bool value);
void variantInit(tr_variant* init_me, int64_t value);
void variantInit(tr_variant* init_me, int value);
void variantInit(tr_variant* init_me, unsigned int value);
void variantInit(tr_variant* init_me, double value);
void variantInit(tr_variant* init_me, QByteArray const& value);
void variantInit(tr_variant* init_me, QString const& value);