attempt to speed up client_test's loading of torrents
This commit is contained in:
parent
13b1628f7a
commit
11038aeecb
|
@ -829,11 +829,20 @@ void scan_dir(std::string const& dir_path
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
std::vector<std::pair<boost::uint64_t, std::string> > ents;
|
||||||
// TODO: don't use internal directory type
|
// TODO: don't use internal directory type
|
||||||
for (directory i(dir_path, ec); !i.done(); i.next(ec))
|
for (directory i(dir_path, ec); !i.done(); i.next(ec))
|
||||||
{
|
{
|
||||||
std::string file = combine_path(dir_path, i.file());
|
if (extension(i.file()) != ".torrent") continue;
|
||||||
if (extension(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);
|
handles_t::iterator k = files.find(file);
|
||||||
if (k != files.end())
|
if (k != files.end())
|
||||||
|
|
|
@ -160,10 +160,12 @@ namespace libtorrent
|
||||||
~directory();
|
~directory();
|
||||||
void next(error_code& ec);
|
void next(error_code& ec);
|
||||||
std::string file() const;
|
std::string file() const;
|
||||||
|
boost::uint64_t inode() const;
|
||||||
bool done() const { return m_done; }
|
bool done() const { return m_done; }
|
||||||
private:
|
private:
|
||||||
#ifdef TORRENT_WINDOWS
|
#ifdef TORRENT_WINDOWS
|
||||||
HANDLE m_handle;
|
HANDLE m_handle;
|
||||||
|
int m_inode;
|
||||||
#if TORRENT_USE_WSTRING
|
#if TORRENT_USE_WSTRING
|
||||||
WIN32_FIND_DATAW m_fd;
|
WIN32_FIND_DATAW m_fd;
|
||||||
#else
|
#else
|
||||||
|
|
11
src/file.cpp
11
src/file.cpp
|
@ -793,6 +793,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
ec.clear();
|
ec.clear();
|
||||||
#ifdef TORRENT_WINDOWS
|
#ifdef TORRENT_WINDOWS
|
||||||
|
m_inode = 0;
|
||||||
// the path passed to FindFirstFile() must be
|
// the path passed to FindFirstFile() must be
|
||||||
// a pattern
|
// a pattern
|
||||||
std::string f = convert_separators(path);
|
std::string f = convert_separators(path);
|
||||||
|
@ -846,6 +847,15 @@ namespace libtorrent
|
||||||
#endif
|
#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
|
std::string directory::file() const
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_WINDOWS
|
#ifdef TORRENT_WINDOWS
|
||||||
|
@ -875,6 +885,7 @@ namespace libtorrent
|
||||||
if (err != ERROR_NO_MORE_FILES)
|
if (err != ERROR_NO_MORE_FILES)
|
||||||
ec.assign(err, boost::system::get_system_category());
|
ec.assign(err, boost::system::get_system_category());
|
||||||
}
|
}
|
||||||
|
++m_inode;
|
||||||
#else
|
#else
|
||||||
dirent* dummy;
|
dirent* dummy;
|
||||||
if (readdir_r(m_handle, &m_dirent, &dummy) != 0)
|
if (readdir_r(m_handle, &m_dirent, &dummy) != 0)
|
||||||
|
|
Loading…
Reference in New Issue