attempt to speed up client_test's loading of torrents

This commit is contained in:
Arvid Norberg 2014-01-19 04:11:49 +00:00
parent 13b1628f7a
commit 11038aeecb
3 changed files with 24 additions and 2 deletions

View File

@ -829,11 +829,20 @@ void scan_dir(std::string const& dir_path
using namespace libtorrent;
error_code ec;
std::vector<std::pair<boost::uint64_t, std::string> > ents;
// TODO: don't use internal directory type
for (directory i(dir_path, ec); !i.done(); i.next(ec))
{
std::string file = combine_path(dir_path, i.file());
if (extension(file) != ".torrent") continue;
if (extension(i.file()) != ".torrent") continue;
ents.push_back(std::make_pair(i.inode(), i.file()));
}
std::sort(ents.begin(), ents.end());
for (std::vector<std::pair<boost::uint64_t, std::string> >::iterator i = ents.begin()
, end(ents.end()); i != end; ++i)
{
std::string file = combine_path(dir_path, i->second);
handles_t::iterator k = files.find(file);
if (k != files.end())

View File

@ -160,10 +160,12 @@ namespace libtorrent
~directory();
void next(error_code& ec);
std::string file() const;
boost::uint64_t inode() const;
bool done() const { return m_done; }
private:
#ifdef TORRENT_WINDOWS
HANDLE m_handle;
int m_inode;
#if TORRENT_USE_WSTRING
WIN32_FIND_DATAW m_fd;
#else

View File

@ -793,6 +793,7 @@ namespace libtorrent
{
ec.clear();
#ifdef TORRENT_WINDOWS
m_inode = 0;
// the path passed to FindFirstFile() must be
// a pattern
std::string f = convert_separators(path);
@ -846,6 +847,15 @@ namespace libtorrent
#endif
}
boost::uint64_t directory::inode() const
{
#ifdef TORRENT_WINDOWS
return m_inode;
#else
return m_dirent.d_ino;
#endif
}
std::string directory::file() const
{
#ifdef TORRENT_WINDOWS
@ -875,6 +885,7 @@ namespace libtorrent
if (err != ERROR_NO_MORE_FILES)
ec.assign(err, boost::system::get_system_category());
}
++m_inode;
#else
dirent* dummy;
if (readdir_r(m_handle, &m_dirent, &dummy) != 0)