minor cleanup/refactor (#1062)

This commit is contained in:
Alden Torres 2016-09-04 18:24:20 -04:00 committed by Arvid Norberg
parent 728e74eca7
commit e11f233086
7 changed files with 16 additions and 40 deletions

View File

@ -42,11 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cstdint> #include <cstdint>
#include "libtorrent/debug.hpp" #include "libtorrent/debug.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/optional.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/buffer.hpp" #include "libtorrent/buffer.hpp"
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"

View File

@ -38,10 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <cstdint> #include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/optional.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/web_connection_base.hpp" #include "libtorrent/web_connection_base.hpp"
#include "libtorrent/piece_block_progress.hpp" #include "libtorrent/piece_block_progress.hpp"

View File

@ -74,10 +74,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cstdint> #include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent namespace libtorrent

View File

@ -40,12 +40,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <cstdint> #include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/optional.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/web_connection_base.hpp" #include "libtorrent/web_connection_base.hpp"
#include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/disk_buffer_holder.hpp"
@ -153,4 +147,3 @@ namespace libtorrent
} }
#endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED #endif // TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED

View File

@ -3321,8 +3321,8 @@ namespace libtorrent
TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index); TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index);
TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index); TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index);
TORRENT_ASSERT(int(block.piece_index) < t->torrent_file().num_pieces()); TORRENT_ASSERT(block.piece_index < t->torrent_file().num_pieces());
TORRENT_ASSERT(int(block.block_index) < t->torrent_file().piece_size(block.piece_index)); TORRENT_ASSERT(block.block_index < t->torrent_file().piece_size(block.piece_index));
TORRENT_ASSERT(!t->picker().is_requested(block) || (t->picker().num_peers(block) > 0)); TORRENT_ASSERT(!t->picker().is_requested(block) || (t->picker().num_peers(block) > 0));
TORRENT_ASSERT(!t->have_piece(block.piece_index)); TORRENT_ASSERT(!t->have_piece(block.piece_index));
TORRENT_ASSERT(std::find_if(m_download_queue.begin(), m_download_queue.end() TORRENT_ASSERT(std::find_if(m_download_queue.begin(), m_download_queue.end()

View File

@ -3143,7 +3143,7 @@ get_out:
TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index); TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index);
TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index); TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index);
TORRENT_ASSERT(block.piece_index < m_piece_map.size()); TORRENT_ASSERT(block.piece_index < m_piece_map.size());
TORRENT_ASSERT(int(block.block_index) < blocks_in_piece(block.piece_index)); TORRENT_ASSERT(block.block_index < blocks_in_piece(block.piece_index));
piece_pos const& p = m_piece_map[block.piece_index]; piece_pos const& p = m_piece_map[block.piece_index];
if (!p.downloading()) return 0; if (!p.downloading()) return 0;

View File

@ -3816,9 +3816,8 @@ namespace libtorrent
TORRENT_ASSERT(st.total_done >= st.total_wanted_done); TORRENT_ASSERT(st.total_done >= st.total_wanted_done);
std::map<piece_block, int> downloading_piece; std::map<piece_block, int> downloading_piece;
for (const_peer_iterator i = begin(); i != end(); ++i) for (auto const& pc : *this)
{ {
peer_connection* pc = *i;
piece_block_progress p = pc->downloading_piece_progress(); piece_block_progress p = pc->downloading_piece_progress();
if (p.piece_index == piece_block_progress::invalid_index) if (p.piece_index == piece_block_progress::invalid_index)
continue; continue;
@ -3830,8 +3829,7 @@ namespace libtorrent
if (m_picker->is_finished(block)) if (m_picker->is_finished(block))
continue; continue;
std::map<piece_block, int>::iterator dp auto dp = downloading_piece.find(block);
= downloading_piece.find(block);
if (dp != downloading_piece.end()) if (dp != downloading_piece.end())
{ {
if (dp->second < p.bytes_downloaded) if (dp->second < p.bytes_downloaded)
@ -3845,12 +3843,11 @@ namespace libtorrent
TORRENT_ASSERT(p.full_block_bytes == to_req(piece_block( TORRENT_ASSERT(p.full_block_bytes == to_req(piece_block(
p.piece_index, p.block_index)).length); p.piece_index, p.block_index)).length);
} }
for (std::map<piece_block, int>::iterator i = downloading_piece.begin(); for (auto const& p : downloading_piece)
i != downloading_piece.end(); ++i)
{ {
int done = (std::min)(block_bytes_wanted(i->first), i->second); int done = (std::min)(block_bytes_wanted(p.first), p.second);
st.total_done += done; st.total_done += done;
if (m_picker->piece_priority(i->first.piece_index) != 0) if (m_picker->piece_priority(p.first.piece_index) != 0)
st.total_wanted_done += done; st.total_wanted_done += done;
} }
@ -3861,14 +3858,13 @@ namespace libtorrent
if (st.total_done >= m_torrent_file->total_size()) if (st.total_done >= m_torrent_file->total_size())
{ {
// Thist happens when a piece has been downloaded completely // This happens when a piece has been downloaded completely
// but not yet verified against the hash // but not yet verified against the hash
std::fprintf(stderr, "num_have: %d\nunfinished:\n", num_have()); std::fprintf(stderr, "num_have: %d\nunfinished:\n", num_have());
for (std::vector<piece_picker::downloading_piece>::const_iterator i = for (auto const& dp : dl_queue)
dl_queue.begin(); i != dl_queue.end(); ++i)
{ {
std::fprintf(stderr, " %d ", i->index); std::fprintf(stderr, " %d ", dp.index);
piece_picker::block_info* info = m_picker->blocks_for_piece(*i); piece_picker::block_info* info = m_picker->blocks_for_piece(dp);
for (int j = 0; j < blocks_per_piece; ++j) for (int j = 0; j < blocks_per_piece; ++j)
{ {
char const* state = info[j].state char const* state = info[j].state
@ -3880,10 +3876,9 @@ namespace libtorrent
fputs("downloading pieces:\n", stderr); fputs("downloading pieces:\n", stderr);
for (std::map<piece_block, int>::iterator i = downloading_piece.begin(); for (auto const& p : downloading_piece)
i != downloading_piece.end(); ++i)
{ {
std::fprintf(stderr, " %d:%d %d\n", int(i->first.piece_index), int(i->first.block_index), i->second); std::fprintf(stderr, " %d:%d %d\n", p.first.piece_index, p.first.block_index, p.second);
} }
} }
@ -10679,8 +10674,8 @@ namespace libtorrent
if (info[k].state == piece_picker::block_info::state_requested) if (info[k].state == piece_picker::block_info::state_requested)
{ {
block = 0; block = 0;
torrent_peer* p = static_cast<torrent_peer*>(info[k].peer); torrent_peer* p = info[k].peer;
if (p && p->connection) if (p != nullptr && p->connection)
{ {
peer_connection* peer = static_cast<peer_connection*>(p->connection); peer_connection* peer = static_cast<peer_connection*>(p->connection);
auto pbp = peer->downloading_piece_progress(); auto pbp = peer->downloading_piece_progress();