diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index b86a511a3..f929fc47c 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -44,7 +44,6 @@ #include #endif -#include #include #include #include @@ -1250,13 +1249,17 @@ QVector TorrentImpl::peers() const QBitArray TorrentImpl::pieces() const { - QBitArray result(m_nativeStatus.pieces.size()); - for (int i = 0; i < result.size(); ++i) + if (m_pieces.isEmpty()) { - if (m_nativeStatus.pieces[lt::piece_index_t {i}]) - result.setBit(i, true); + m_pieces.resize(m_nativeStatus.pieces.size()); + for (int i = 0; i < m_pieces.size(); ++i) + { + if (m_nativeStatus.pieces[lt::piece_index_t(i)]) + m_pieces.setBit(i, true); + } } - return result; + + return m_pieces; } QBitArray TorrentImpl::downloadingPieces() const @@ -2094,6 +2097,7 @@ void TorrentImpl::updateStatus() void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus) { + m_pieces.clear(); m_nativeStatus = nativeStatus; updateState(); diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index e39056527..9c953741f 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -320,5 +321,7 @@ namespace BitTorrent bool m_unchecked = false; lt::add_torrent_params m_ltAddTorrentParams; + + mutable QBitArray m_pieces; }; }