From 58ce7bd437bb62c57796293401c9c8432038d74e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 20 Mar 2023 21:08:16 -0500 Subject: [PATCH] fix: 4.0.2 wishlist CPU perf regression pt. 1 (#5266) --- .github/workflows/actions.yml | 1 + libtransmission/file-piece-map.cc | 15 +++++---------- libtransmission/file-piece-map.h | 8 ++++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index a92bd4810..53226fcda 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -738,6 +738,7 @@ jobs: set -ex sudo apt-get update sudo apt-get install -y --no-install-recommends \ + appstream \ ca-certificates \ clang \ cmake \ diff --git a/libtransmission/file-piece-map.cc b/libtransmission/file-piece-map.cc index 5935bf7bf..5a762919c 100644 --- a/libtransmission/file-piece-map.cc +++ b/libtransmission/file-piece-map.cc @@ -62,17 +62,17 @@ void tr_file_piece_map::reset(tr_torrent_metainfo const& tm) tr_file_piece_map::file_span_t tr_file_piece_map::fileSpan(tr_piece_index_t piece) const { - auto compare = CompareToSpan{}; + constexpr auto Compare = CompareToSpan{}; auto const begin = std::begin(file_pieces_); - auto const& [equal_begin, equal_end] = std::equal_range(begin, std::end(file_pieces_), piece, compare); - return { tr_piece_index_t(std::distance(begin, equal_begin)), tr_piece_index_t(std::distance(begin, equal_end)) }; + auto const& [equal_begin, equal_end] = std::equal_range(begin, std::end(file_pieces_), piece, Compare); + return { tr_piece_index_t(equal_begin - begin), tr_piece_index_t(equal_end - begin) }; } tr_file_piece_map::file_offset_t tr_file_piece_map::fileOffset(uint64_t offset) const { - auto compare = CompareToSpan{}; + constexpr auto Compare = CompareToSpan{}; auto const begin = std::begin(file_bytes_); - auto const it = std::lower_bound(begin, std::end(file_bytes_), offset, compare); + auto const it = std::lower_bound(begin, std::end(file_bytes_), offset, Compare); tr_file_index_t const file_index = std::distance(begin, it); auto const file_offset = offset - it->begin; return file_offset_t{ file_index, file_offset }; @@ -124,11 +124,6 @@ tr_priority_t tr_file_priorities::filePriority(tr_file_index_t file) const tr_priority_t tr_file_priorities::piecePriority(tr_piece_index_t piece) const { - if (std::empty(*fpm_)) // not initialized yet - { - return TR_PRI_NORMAL; - } - // increase priority if a file begins or ends in this piece // because that makes life easier for code/users using at incomplete files. // Xrefs: f2daeb242, https://forum.transmissionbt.com/viewtopic.php?t=10473 diff --git a/libtransmission/file-piece-map.h b/libtransmission/file-piece-map.h index d87356e5e..19e577c76 100644 --- a/libtransmission/file-piece-map.h +++ b/libtransmission/file-piece-map.h @@ -89,7 +89,7 @@ private: { using span_t = index_span_t; - int compare(T item, span_t span) const // <=> + [[nodiscard]] constexpr int compare(T item, span_t span) const // <=> { if (item < span.begin) { @@ -104,17 +104,17 @@ private: return 0; } - bool operator()(T item, span_t span) const // < + [[nodiscard]] constexpr bool operator()(T item, span_t span) const // < { return compare(item, span) < 0; } - int compare(span_t span, T item) const // <=> + [[nodiscard]] constexpr int compare(span_t span, T item) const // <=> { return -compare(item, span); } - bool operator()(span_t span, T item) const // < + [[nodiscard]] constexpr bool operator()(span_t span, T item) const // < { return compare(span, item) < 0; }