more use of index range and lint oriented refactor in torrent.cpp

This commit is contained in:
Alden Torres 2018-09-04 09:29:17 -04:00 committed by Arvid Norberg
parent c9cbb122e2
commit 9b2f6042bb
1 changed files with 8 additions and 11 deletions

View File

@ -4801,7 +4801,7 @@ bool is_downloading_state(int const st)
return; return;
} }
TORRENT_ASSERT(m_picker.get()); TORRENT_ASSERT(m_picker);
m_picker->piece_priorities(*pieces); m_picker->piece_priorities(*pieces);
} }
@ -6088,7 +6088,7 @@ bool is_downloading_state(int const st)
: m_files_checked ? m_torrent_file->end_piece() : m_files_checked ? m_torrent_file->end_piece()
: piece_index_t(0); : piece_index_t(0);
TORRENT_ASSERT(ret.have_pieces.size() == 0); TORRENT_ASSERT(ret.have_pieces.empty());
if (max_piece > piece_index_t(0)) if (max_piece > piece_index_t(0))
{ {
if (is_seed()) if (is_seed())
@ -6098,10 +6098,8 @@ bool is_downloading_state(int const st)
else if (has_picker()) else if (has_picker())
{ {
ret.have_pieces.resize(static_cast<int>(max_piece), false); ret.have_pieces.resize(static_cast<int>(max_piece), false);
for (piece_index_t i(0); i < max_piece; ++i) for (auto const i : ret.have_pieces.range())
{
if (m_picker->have_piece(i)) ret.have_pieces.set_bit(i); if (m_picker->have_piece(i)) ret.have_pieces.set_bit(i);
}
} }
if (m_seed_mode) if (m_seed_mode)
@ -6196,8 +6194,7 @@ bool is_downloading_state(int const st)
// write piece priorities // write piece priorities
// but only if they are not set to the default // but only if they are not set to the default
bool default_prio = true; bool default_prio = true;
file_storage const& fs = m_torrent_file->files(); for (auto const i : m_torrent_file->piece_range())
for (piece_index_t i(0); i < fs.end_piece(); ++i)
{ {
if (m_picker->piece_priority(i) == default_priority) continue; if (m_picker->piece_priority(i) == default_priority) continue;
default_prio = false; default_prio = false;
@ -6209,7 +6206,7 @@ bool is_downloading_state(int const st)
ret.piece_priorities.clear(); ret.piece_priorities.clear();
ret.piece_priorities.reserve(static_cast<std::size_t>(m_torrent_file->num_pieces())); ret.piece_priorities.reserve(static_cast<std::size_t>(m_torrent_file->num_pieces()));
for (piece_index_t i(0); i < fs.end_piece(); ++i) for (auto const i : m_torrent_file->piece_range())
ret.piece_priorities.push_back(m_picker->piece_priority(i)); ret.piece_priorities.push_back(m_picker->piece_priority(i));
} }
} }
@ -9354,7 +9351,7 @@ bool is_downloading_state(int const st)
{ {
int peers; int peers;
int index; int index;
bool operator<(busy_block_t rhs) const { return peers < rhs.peers; } bool operator<(busy_block_t const& rhs) const { return peers < rhs.peers; }
}; };
void pick_busy_blocks(piece_picker const* picker void pick_busy_blocks(piece_picker const* picker
@ -9510,7 +9507,7 @@ bool is_downloading_state(int const st)
// move on to the next one // move on to the next one
if (interesting_blocks.empty()) break; if (interesting_blocks.empty()) break;
piece_block b = interesting_blocks.front(); piece_block const b = interesting_blocks.front();
// in busy mode we need to make sure we don't do silly // in busy mode we need to make sure we don't do silly
// things like requesting the same block twice from the // things like requesting the same block twice from the
@ -10660,7 +10657,7 @@ bool is_downloading_state(int const st)
if (has_picker()) if (has_picker())
{ {
st->pieces.resize(num_pieces, false); st->pieces.resize(num_pieces, false);
for (piece_index_t i(0); i < piece_index_t(num_pieces); ++i) for (auto const i : st->pieces.range())
if (m_picker->has_piece_passed(i)) st->pieces.set_bit(i); if (m_picker->has_piece_passed(i)) st->pieces.set_bit(i);
} }
else if (m_have_all) else if (m_have_all)