make torrent_status movable and don't allocate pieces unless it's asked for

This commit is contained in:
arvidn 2017-03-25 14:45:23 -04:00 committed by Arvid Norberg
parent 2c131dbbc4
commit 8e6f417015
5 changed files with 25 additions and 19 deletions

View File

@ -312,7 +312,7 @@ namespace libtorrent
query_accurate_download_counters = 2,
// includes ``last_seen_complete``.
query_last_seen_complete = 4,
// includes ``pieces``.
// populate the ``pieces`` field in torrent_status.
query_pieces = 8,
// includes ``verified_pieces`` (only applies to torrents in *seed
// mode*).
@ -1257,11 +1257,11 @@ namespace libtorrent
// comparison operators. The order of the torrents is unspecified
// but stable.
bool operator==(const torrent_handle& h) const
{ return m_torrent.lock() == h.m_torrent.lock(); }
{ return !m_torrent.owner_before(h.m_torrent) && !h.m_torrent.owner_before(m_torrent); }
bool operator!=(const torrent_handle& h) const
{ return m_torrent.lock() != h.m_torrent.lock(); }
{ return m_torrent.owner_before(h.m_torrent) || h.m_torrent.owner_before(m_torrent); }
bool operator<(const torrent_handle& h) const
{ return m_torrent.lock() < h.m_torrent.lock(); }
{ return m_torrent.owner_before(h.m_torrent); }
std::uint32_t id() const
{

View File

@ -56,6 +56,8 @@ namespace libtorrent
~torrent_status();
torrent_status(torrent_status const&);
torrent_status& operator=(torrent_status const&);
torrent_status(torrent_status&&);
torrent_status& operator=(torrent_status&&);
// compares if the torrent status objects come from the same torrent. i.e.
// only the torrent_handle field is compared.

View File

@ -5050,8 +5050,7 @@ namespace aux {
// this torrent might be filed under the URL-hash
if (i == m_torrents.end() && !tptr->url().empty())
{
std::string const& url = tptr->url();
i = m_torrents.find(hasher(url).final());
i = m_torrents.find(hasher(tptr->url()).final());
}
#endif

View File

@ -10531,20 +10531,23 @@ namespace libtorrent
#endif
}
int num_pieces = m_torrent_file->num_pieces();
if (has_picker() && (flags & torrent_handle::query_pieces))
if (flags & torrent_handle::query_pieces)
{
st->pieces.resize(num_pieces, false);
for (piece_index_t i(0); i < piece_index_t(num_pieces); ++i)
if (m_picker->has_piece_passed(i)) st->pieces.set_bit(i);
}
else if (m_have_all)
{
st->pieces.resize(num_pieces, true);
}
else
{
st->pieces.resize(num_pieces, false);
int const num_pieces = m_torrent_file->num_pieces();
if (has_picker())
{
st->pieces.resize(num_pieces, false);
for (piece_index_t i(0); i < piece_index_t(num_pieces); ++i)
if (m_picker->has_piece_passed(i)) st->pieces.set_bit(i);
}
else if (m_have_all)
{
st->pieces.resize(num_pieces, true);
}
else
{
st->pieces.resize(num_pieces, false);
}
}
st->num_pieces = num_have();
st->num_seeds = num_seeds() - int(m_num_connecting_seeds);

View File

@ -43,4 +43,6 @@ namespace libtorrent
torrent_status::~torrent_status() = default;
torrent_status::torrent_status(torrent_status const&) = default;
torrent_status& torrent_status::operator=(torrent_status const&) = default;
torrent_status::torrent_status(torrent_status&&) = default;
torrent_status& torrent_status::operator=(torrent_status&&) = default;
}