diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 335d64682..1c2eec8d2 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -149,6 +149,8 @@ namespace libtorrent downloading_piece(): state(none), index(-1), info(0) , finished(0), writing(0), requested(0) {} + bool operator<(downloading_piece const& rhs) const { return index < rhs.index; } + piece_state_t state; // the index of the piece @@ -353,14 +355,6 @@ namespace libtorrent int index; }; - struct compare_index - { - bool operator()(const downloading_piece& p, int piece) const - { return p.index < piece; } - bool operator()(int piece, const downloading_piece& p) const - { return piece < p.index; } - }; - int blocks_in_last_piece() const { return m_blocks_in_last_piece; } diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index f4ba1595b..9dda533c5 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -171,8 +171,10 @@ namespace libtorrent m_downloads[i].info = &m_block_info[m_downloads[i].info - base]; } } + downloading_piece cmp; + cmp.index = piece; std::vector::iterator i = std::lower_bound(m_downloads.begin() - , m_downloads.end(), piece, compare_index()); + , m_downloads.end(), cmp); TORRENT_ASSERT(i == m_downloads.end() || i->index != piece); i = m_downloads.insert(i, downloading_piece()); downloading_piece& ret = *i; @@ -1990,8 +1992,10 @@ namespace libtorrent std::vector::iterator piece_picker::find_dl_piece(int index) { // return std::find_if(m_downloads.begin(), m_downloads.end(), has_index(index)); + downloading_piece cmp; + cmp.index = index; std::vector::iterator i = std::lower_bound( - m_downloads.begin(), m_downloads.end(), index, compare_index()); + m_downloads.begin(), m_downloads.end(), cmp); if (i == m_downloads.end()) return i; if (i->index == index) return i; return m_downloads.end(); @@ -2000,8 +2004,10 @@ namespace libtorrent std::vector::const_iterator piece_picker::find_dl_piece(int index) const { // return std::find_if(m_downloads.begin(), m_downloads.end(), has_index(index)); + downloading_piece cmp; + cmp.index = index; std::vector::const_iterator i = std::lower_bound( - m_downloads.begin(), m_downloads.end(), index, compare_index()); + m_downloads.begin(), m_downloads.end(), cmp); if (i == m_downloads.end()) return i; if (i->index == index) return i; return m_downloads.end();