mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
refactor: more constexpr (#4518)
This commit is contained in:
@@ -109,7 +109,8 @@ public:
|
||||
bool remove(tr_tracker_id_t id);
|
||||
bool replace(tr_tracker_id_t id, std::string_view announce_url_sv);
|
||||
size_t set(char const* const* announce_urls, tr_tracker_tier_t const* tiers, size_t n);
|
||||
void clear()
|
||||
|
||||
TR_CONSTEXPR20 void clear()
|
||||
{
|
||||
return trackers_.clear();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
return have_none_hint_ || (bit_count_ > 0 && true_count_ == 0);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool test(size_t bit) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 bool test(size_t bit) const
|
||||
{
|
||||
return hasAll() || (!hasNone() && testFlag(bit));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ struct tr_completion
|
||||
return hasMetainfo() && blocks_.hasAll();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool hasBlock(tr_block_index_t block) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 bool hasBlock(tr_block_index_t block) const
|
||||
{
|
||||
return blocks_.test(block);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
void set(tr_file_index_t file, bool wanted);
|
||||
void set(tr_file_index_t const* files, size_t n, bool wanted);
|
||||
|
||||
[[nodiscard]] bool fileWanted(tr_file_index_t file) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 bool fileWanted(tr_file_index_t file) const
|
||||
{
|
||||
return wanted_.test(file);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
* @param when the current time in sec, such as from tr_time()
|
||||
* @param seconds how many seconds to count back through.
|
||||
*/
|
||||
constexpr SizeType count(time_t now, unsigned int age_sec) const
|
||||
[[nodiscard]] constexpr SizeType count(time_t now, unsigned int age_sec) const
|
||||
{
|
||||
auto sum = SizeType{};
|
||||
time_t const oldest = now - age_sec;
|
||||
|
||||
@@ -26,7 +26,7 @@ struct tr_torrent;
|
||||
* Reads the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioRead(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t* setme);
|
||||
[[nodiscard]] int tr_ioRead(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t* setme);
|
||||
|
||||
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len);
|
||||
|
||||
@@ -34,7 +34,7 @@ int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len);
|
||||
* Writes the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioWrite(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t const* writeme);
|
||||
[[nodiscard]] int tr_ioWrite(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t const* writeme);
|
||||
|
||||
/**
|
||||
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
files_.shrink_to_fit();
|
||||
}
|
||||
|
||||
void clear() noexcept
|
||||
TR_CONSTEXPR20 void clear() noexcept
|
||||
{
|
||||
files_.clear();
|
||||
total_size_ = uint64_t{};
|
||||
|
||||
@@ -153,24 +153,6 @@ public:
|
||||
return bandwidth_.isLimited(dir);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto isPieceTransferAllowed(tr_direction direction) const noexcept
|
||||
{
|
||||
if (usesSpeedLimit(direction) && speedLimitBps(direction) <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (usesSessionLimits())
|
||||
{
|
||||
if (auto const limit = session->activeSpeedLimitBps(direction); limit && *limit == 0U)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// BLOCK INFO
|
||||
|
||||
[[nodiscard]] constexpr auto const& blockInfo() const noexcept
|
||||
@@ -251,7 +233,7 @@ public:
|
||||
return completion.hasPiece(piece);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto hasBlock(tr_block_index_t block) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto hasBlock(tr_block_index_t block) const
|
||||
{
|
||||
return completion.hasBlock(block);
|
||||
}
|
||||
@@ -332,7 +314,7 @@ public:
|
||||
return files_wanted_.pieceWanted(piece);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool fileIsWanted(tr_file_index_t file) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 bool fileIsWanted(tr_file_index_t file) const
|
||||
{
|
||||
return files_wanted_.fileWanted(file);
|
||||
}
|
||||
@@ -536,7 +518,7 @@ public:
|
||||
|
||||
/// METAINFO - PIECE CHECKSUMS
|
||||
|
||||
[[nodiscard]] bool isPieceChecked(tr_piece_index_t piece) const
|
||||
[[nodiscard]] TR_CONSTEXPR20 bool isPieceChecked(tr_piece_index_t piece) const
|
||||
{
|
||||
return checked_pieces_.test(piece);
|
||||
}
|
||||
@@ -574,12 +556,12 @@ public:
|
||||
return this->isPublic() && this->session->allowsLPD();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool clientCanDownload() const
|
||||
[[nodiscard]] constexpr bool clientCanDownload() const
|
||||
{
|
||||
return this->isPieceTransferAllowed(TR_PEER_TO_CLIENT);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool clientCanUpload() const
|
||||
[[nodiscard]] constexpr bool clientCanUpload() const
|
||||
{
|
||||
return this->isPieceTransferAllowed(TR_CLIENT_TO_PEER);
|
||||
}
|
||||
@@ -911,6 +893,24 @@ public:
|
||||
bool magnetVerify = false;
|
||||
|
||||
private:
|
||||
[[nodiscard]] constexpr bool isPieceTransferAllowed(tr_direction direction) const noexcept
|
||||
{
|
||||
if (usesSpeedLimit(direction) && speedLimitBps(direction) <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (usesSessionLimits())
|
||||
{
|
||||
if (auto const limit = session->activeSpeedLimitBps(direction); limit && *limit == 0U)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping)
|
||||
{
|
||||
auto const lock = unique_lock();
|
||||
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
|
||||
// Note that tr_web does no management of the `mediator` reference.
|
||||
// The caller must ensure `mediator` is valid for tr_web's lifespan.
|
||||
static std::unique_ptr<tr_web> create(Mediator& mediator);
|
||||
[[nodiscard]] static std::unique_ptr<tr_web> create(Mediator& mediator);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
||||
Reference in New Issue
Block a user