perf: pass by reference (#4876)

This commit is contained in:
midzer 2023-04-15 00:06:26 +02:00 committed by GitHub
parent d445c7f061
commit 68e965aa28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 17 deletions

View File

@ -419,7 +419,7 @@ struct tr_tier
return currentTracker(); return currentTracker();
} }
[[nodiscard]] std::optional<size_t> indexOf(tr_interned_string const& announce_url) const [[nodiscard]] std::optional<size_t> indexOf(tr_interned_string announce_url) const
{ {
for (size_t i = 0, n = std::size(trackers); i < n; ++i) for (size_t i = 0, n = std::size(trackers); i < n; ++i)
{ {
@ -579,7 +579,7 @@ struct tr_torrent_announcer
return nullptr; return nullptr;
} }
tr_tier* getTierFromScrape(tr_interned_string const& scrape_url) tr_tier* getTierFromScrape(tr_interned_string scrape_url)
{ {
for (auto& tier : tiers) for (auto& tier : tiers)
{ {
@ -600,7 +600,7 @@ struct tr_torrent_announcer
} }
[[nodiscard]] bool findTracker( [[nodiscard]] bool findTracker(
tr_interned_string const& announce_url, tr_interned_string announce_url,
tr_tier const** setme_tier, tr_tier const** setme_tier,
tr_tracker const** setme_tracker) const tr_tracker const** setme_tracker) const
{ {

View File

@ -161,7 +161,7 @@ int Cache::writeBlock(tr_torrent_id_t tor_id, tr_block_index_t block, std::uniqu
return cacheTrim(); return cacheTrim();
} }
Cache::CIter Cache::getBlock(tr_torrent const* torrent, tr_block_info::Location loc) noexcept Cache::CIter Cache::getBlock(tr_torrent const* torrent, tr_block_info::Location const& loc) noexcept
{ {
if (auto const [begin, end] = std::equal_range( if (auto const [begin, end] = std::equal_range(
std::begin(blocks_), std::begin(blocks_),
@ -176,7 +176,7 @@ Cache::CIter Cache::getBlock(tr_torrent const* torrent, tr_block_info::Location
return std::end(blocks_); return std::end(blocks_);
} }
int Cache::readBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len, uint8_t* setme) int Cache::readBlock(tr_torrent* torrent, tr_block_info::Location const& loc, uint32_t len, uint8_t* setme)
{ {
if (auto const iter = getBlock(torrent, loc); iter != std::end(blocks_)) if (auto const iter = getBlock(torrent, loc); iter != std::end(blocks_))
{ {
@ -187,7 +187,7 @@ int Cache::readBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t
return tr_ioRead(torrent, loc, len, setme); return tr_ioRead(torrent, loc, len, setme);
} }
int Cache::prefetchBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len) int Cache::prefetchBlock(tr_torrent* torrent, tr_block_info::Location const& loc, uint32_t len)
{ {
if (auto const iter = getBlock(torrent, loc); iter != std::end(blocks_)) if (auto const iter = getBlock(torrent, loc); iter != std::end(blocks_))
{ {

View File

@ -38,8 +38,8 @@ public:
// @return any error code from cacheTrim() // @return any error code from cacheTrim()
int writeBlock(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<std::vector<uint8_t>> writeme); int writeBlock(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<std::vector<uint8_t>> writeme);
int readBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len, uint8_t* setme); int readBlock(tr_torrent* torrent, tr_block_info::Location const& loc, uint32_t len, uint8_t* setme);
int prefetchBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len); int prefetchBlock(tr_torrent* torrent, tr_block_info::Location const& loc, uint32_t len);
int flushTorrent(tr_torrent const* torrent); int flushTorrent(tr_torrent const* torrent);
int flushFile(tr_torrent const* torrent, tr_file_index_t file); int flushFile(tr_torrent const* torrent, tr_file_index_t file);
@ -86,7 +86,7 @@ private:
[[nodiscard]] static size_t getMaxBlocks(int64_t max_bytes) noexcept; [[nodiscard]] static size_t getMaxBlocks(int64_t max_bytes) noexcept;
[[nodiscard]] CIter getBlock(tr_torrent const* torrent, tr_block_info::Location loc) noexcept; [[nodiscard]] CIter getBlock(tr_torrent const* torrent, tr_block_info::Location const& loc) noexcept;
tr_torrents& torrents_; tr_torrents& torrents_;

View File

@ -282,17 +282,17 @@ std::optional<tr_sha1_digest_t> recalculateHash(tr_torrent* tor, tr_piece_index_
} // namespace } // namespace
int tr_ioRead(tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t* setme) int tr_ioRead(tr_torrent* tor, tr_block_info::Location const& loc, size_t len, uint8_t* setme)
{ {
return readOrWritePiece(tor, IoMode::Read, loc, setme, len); return readOrWritePiece(tor, IoMode::Read, loc, setme, len);
} }
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len) int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location const& loc, size_t len)
{ {
return readOrWritePiece(tor, IoMode::Prefetch, loc, nullptr, len); return readOrWritePiece(tor, IoMode::Prefetch, loc, nullptr, len);
} }
int tr_ioWrite(tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t const* writeme) int tr_ioWrite(tr_torrent* tor, tr_block_info::Location const& loc, size_t len, uint8_t const* writeme)
{ {
return readOrWritePiece(tor, IoMode::Write, loc, const_cast<uint8_t*>(writeme), len); return readOrWritePiece(tor, IoMode::Write, loc, const_cast<uint8_t*>(writeme), len);
} }

View File

@ -26,15 +26,15 @@ struct tr_torrent;
* Reads the block specified by the piece index, offset, and length. * Reads the block specified by the piece index, offset, and length.
* @return 0 on success, or an errno value on failure. * @return 0 on success, or an errno value on failure.
*/ */
[[nodiscard]] 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 const& loc, size_t len, uint8_t* setme);
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len); int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location const& loc, size_t len);
/** /**
* Writes the block specified by the piece index, offset, and length. * Writes the block specified by the piece index, offset, and length.
* @return 0 on success, or an errno value on failure. * @return 0 on success, or an errno value on failure.
*/ */
[[nodiscard]] 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 const& loc, size_t len, uint8_t const* writeme);
/** /**
* @brief Test to see if the piece matches its metainfo's SHA1 checksum. * @brief Test to see if the piece matches its metainfo's SHA1 checksum.

View File

@ -2559,8 +2559,8 @@ void renameTorrentFileString(tr_torrent* tor, std::string_view oldpath, std::str
void torrentRenamePath( void torrentRenamePath(
tr_torrent* const tor, tr_torrent* const tor,
std::string oldpath, // NOLINT performance-unnecessary-value-param std::string const& oldpath, // NOLINT performance-unnecessary-value-param
std::string newname, // NOLINT performance-unnecessary-value-param std::string const& newname, // NOLINT performance-unnecessary-value-param
tr_torrent_rename_done_func callback, tr_torrent_rename_done_func callback,
void* const callback_user_data) void* const callback_user_data)
{ {