From 5fd4f6ece2c8727777f0a8d05777bc53f99e90a2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 27 Dec 2003 01:34:50 +0000 Subject: [PATCH] *** empty log message *** --- examples/client_test.cpp | 2 +- include/libtorrent/storage.hpp | 7 ++++--- src/storage.cpp | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index ca8b0a322..37ab8f8e0 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -154,7 +154,7 @@ std::string add_suffix(float val) int i; for (i = 0; i < num_prefix; ++i) { - if (abs(val) < 1024.f) + if (fabs(val) < 1024.f) return to_string(val, i==0?7:6) + prefix[i]; val /= 1024.f; } diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 70c3d6363..c8fb67c63 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -99,9 +99,10 @@ namespace libtorrent const boost::filesystem::path& save_path() const; - // fills the vector with a map of pieces to - // slots, including not-yet-finished piece - void export_piece_map(std::vector >& pieces) const; + // fills the vector that maps all allocated + // slots to the piece that is stored (or + // partially stored) there + void export_piece_map(std::vector& pieces) const; private: struct impl; diff --git a/src/storage.cpp b/src/storage.cpp index 144ff0f16..6dd7214f1 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -370,7 +370,7 @@ namespace libtorrent { const boost::filesystem::path& save_path() const { return m_save_path; } - void export_piece_map(std::vector >& p) const; + void export_piece_map(std::vector& p) const; private: // returns the slot currently associated with the given @@ -430,20 +430,28 @@ namespace libtorrent { } void piece_manager::impl::export_piece_map( - std::vector >& p) const + std::vector& p) const { p.clear(); - for (std::vector::const_iterator i = m_piece_to_slot.begin(); - i != m_piece_to_slot.end(); + std::vector::const_reverse_iterator last; + for (last = m_slot_to_piece.rbegin(); + last != m_slot_to_piece.rend(); + ++last) + { + if (*last != -1) break; + } + + for (std::vector::const_iterator i = + m_slot_to_piece.begin(); + i != last.base(); ++i) { - if (*i == -1) continue; - p.push_back(std::make_pair(i - m_piece_to_slot.begin(), *i)); + p.push_back(*i); } } void piece_manager::export_piece_map( - std::vector >& p) const + std::vector& p) const { m_pimpl->export_piece_map(p); }