Skip to content

Commit

Permalink
fix: 4.0.2 wishlist CPU perf regression pt. 1 (#5266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckerr committed Mar 21, 2023
1 parent 652c466 commit 58ce7bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/actions.yml
Expand Up @@ -738,6 +738,7 @@ jobs:
set -ex
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
appstream \
ca-certificates \
clang \
cmake \
Expand Down
15 changes: 5 additions & 10 deletions libtransmission/file-piece-map.cc
Expand Up @@ -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<tr_piece_index_t>{};
constexpr auto Compare = CompareToSpan<tr_piece_index_t>{};
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<uint64_t>{};
constexpr auto Compare = CompareToSpan<uint64_t>{};
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 };
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions libtransmission/file-piece-map.h
Expand Up @@ -89,7 +89,7 @@ class tr_file_piece_map
{
using span_t = index_span_t<T>;

int compare(T item, span_t span) const // <=>
[[nodiscard]] constexpr int compare(T item, span_t span) const // <=>
{
if (item < span.begin)
{
Expand All @@ -104,17 +104,17 @@ class tr_file_piece_map
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;
}
Expand Down

0 comments on commit 58ce7bd

Please sign in to comment.