forked from premiere/premiere-libtorrent
merge pad_file_at optimization from libtorrent_aio
This commit is contained in:
parent
32b4b5926a
commit
d181b2e057
|
@ -177,12 +177,12 @@ file structure. Its synopsis::
|
|||
sha1_hash const& hash(int index) const;
|
||||
std::string const& symlink(int index) const;
|
||||
time_t mtime(int index) const;
|
||||
int file_index(int index) const;
|
||||
size_type file_base(int index) const;
|
||||
void set_file_base(int index, size_type off);
|
||||
std::string file_path(int index) const;
|
||||
std::string file_name(int index) const;
|
||||
size_type file_size(int index) const;
|
||||
bool pad_file_at(int index) const;
|
||||
size_type file_offset(int index) const;
|
||||
|
||||
// iterator accessors
|
||||
|
@ -195,6 +195,7 @@ file structure. Its synopsis::
|
|||
std::string file_path(internal_file_entry const& fe) const;
|
||||
std::string file_name(internal_file_entry const& fe) const;
|
||||
size_type file_size(internal_file_entry const& fe) const;
|
||||
bool pad_file_at(internal_file_entry const& fe) const;
|
||||
size_type file_offset(internal_file_entry const& fe) const;
|
||||
|
||||
void set_name(std::string const& n);
|
||||
|
@ -231,28 +232,35 @@ can be changed by calling ``set_name``.
|
|||
The built in functions to traverse a directory to add files will
|
||||
make sure this requirement is fulfilled.
|
||||
|
||||
hash() symlink() mtime() file_index()
|
||||
-------------------------------------
|
||||
hash() symlink() mtime() file_path() file_size() pad_file_at()
|
||||
--------------------------------------------------------------
|
||||
|
||||
::
|
||||
|
||||
sha1_hash hash(int index) const;
|
||||
std::string const& symlink(int index) const;
|
||||
time_t mtime(int index) const;
|
||||
int file_index(int index) const;
|
||||
std::string file_path(int index) const;
|
||||
size_type file_size(int index) const;
|
||||
bool pad_file_at(int index) const;
|
||||
|
||||
These functions are used to query the symlink, file hash,
|
||||
modification time and the file-index from a file index.
|
||||
These functions are used to query attributes of files at
|
||||
a given index.
|
||||
|
||||
The file hash is a sha-1 hash of the file, or 0 if none was
|
||||
The ``file_hash()`` is a sha-1 hash of the file, or 0 if none was
|
||||
provided in the torrent file. This can potentially be used to
|
||||
join a bittorrent network with other file sharing networks.
|
||||
|
||||
The modification time is the posix time when a file was last
|
||||
modified when the torrent was created, or 0 if it was not provided.
|
||||
The ``mtime()`` is the modification time is the posix
|
||||
time when a file was last modified when the torrent
|
||||
was created, or 0 if it was not included in the torrent file.
|
||||
|
||||
The file index of a file is simply a 0 based index of the
|
||||
file as they are ordered in the torrent file.
|
||||
``file_path()`` returns the full path to a file.
|
||||
|
||||
``file_size()`` returns the size of a file.
|
||||
|
||||
``pad_file_at()`` returns true if the file at the given
|
||||
index is a pad-file.
|
||||
|
||||
file_base() set_file_base()
|
||||
---------------------------
|
||||
|
|
|
@ -249,12 +249,12 @@ namespace libtorrent
|
|||
sha1_hash hash(int index) const;
|
||||
std::string const& symlink(int index) const;
|
||||
time_t mtime(int index) const;
|
||||
int file_index(int index) const;
|
||||
size_type file_base(int index) const;
|
||||
void set_file_base(int index, size_type off);
|
||||
std::string file_path(int index) const;
|
||||
std::string file_name(int index) const;
|
||||
size_type file_size(int index) const;
|
||||
bool pad_file_at(int index) const;
|
||||
size_type file_offset(int index) const;
|
||||
|
||||
sha1_hash hash(internal_file_entry const& fe) const;
|
||||
|
@ -266,6 +266,7 @@ namespace libtorrent
|
|||
std::string file_path(internal_file_entry const& fe) const;
|
||||
std::string file_name(internal_file_entry const& fe) const;
|
||||
size_type file_size(internal_file_entry const& fe) const;
|
||||
bool pad_file_at(internal_file_entry const& fe) const;
|
||||
size_type file_offset(internal_file_entry const& fe) const;
|
||||
|
||||
#if !defined TORRENT_VERBOSE_LOGGING \
|
||||
|
|
|
@ -398,12 +398,6 @@ namespace libtorrent
|
|||
return m_mtime[index];
|
||||
}
|
||||
|
||||
int file_storage::file_index(int index) const
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
||||
return index;
|
||||
}
|
||||
|
||||
void file_storage::set_file_base(int index, size_type off)
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
||||
|
@ -439,6 +433,12 @@ namespace libtorrent
|
|||
return m_files[index].size;
|
||||
}
|
||||
|
||||
bool file_storage::pad_file_at(int index) const
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
||||
return m_files[index].pad_file;
|
||||
}
|
||||
|
||||
size_type file_storage::file_offset(int index) const
|
||||
{
|
||||
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
|
||||
|
@ -504,6 +504,11 @@ namespace libtorrent
|
|||
return fe.size;
|
||||
}
|
||||
|
||||
bool file_storage::pad_file_at(internal_file_entry const& fe) const
|
||||
{
|
||||
return fe.pad_file;
|
||||
}
|
||||
|
||||
size_type file_storage::file_offset(internal_file_entry const& fe) const
|
||||
{
|
||||
return fe.offset;
|
||||
|
|
|
@ -2849,8 +2849,7 @@ namespace libtorrent
|
|||
for (std::vector<file_slice>::iterator i = files.begin()
|
||||
, end(files.end()); i != end; ++i)
|
||||
{
|
||||
file_entry const& fe = fs.at(i->file_index);
|
||||
if (fe.pad_file) continue;
|
||||
if (fs.pad_file_at(i->file_index)) continue;
|
||||
ret += i->size;
|
||||
}
|
||||
TORRENT_ASSERT(ret <= (std::min)(piece_size - offset, int(block_size())));
|
||||
|
@ -3176,11 +3175,11 @@ namespace libtorrent
|
|||
m_file_progress[file_index] += add;
|
||||
|
||||
TORRENT_ASSERT(m_file_progress[file_index]
|
||||
<= m_torrent_file->files().at(file_index).size);
|
||||
<= m_torrent_file->files().file_size(file_index));
|
||||
|
||||
if (m_file_progress[file_index] >= m_torrent_file->files().at(file_index).size)
|
||||
if (m_file_progress[file_index] >= m_torrent_file->files().file_size(file_index))
|
||||
{
|
||||
if (!m_torrent_file->files().at(file_index).pad_file)
|
||||
if (!m_torrent_file->files().pad_file_at(file_index))
|
||||
{
|
||||
// don't finalize files if we discover that they exist
|
||||
// in whole (i.e. while checking). In that case, just assume
|
||||
|
@ -4181,7 +4180,7 @@ namespace libtorrent
|
|||
for (int i = 0; i < (int)bitmask.size(); ++i)
|
||||
{
|
||||
size_type start = position;
|
||||
position += m_torrent_file->files().at(i).size;
|
||||
position += m_torrent_file->files().file_size(i);
|
||||
// is the file selected for download?
|
||||
if (!bitmask[i])
|
||||
{
|
||||
|
@ -6597,7 +6596,7 @@ namespace libtorrent
|
|||
, end(m_file_progress.end()); i != end; ++i)
|
||||
{
|
||||
int index = i - m_file_progress.begin();
|
||||
TORRENT_ASSERT(*i <= m_torrent_file->files().at(index).size);
|
||||
TORRENT_ASSERT(*i <= m_torrent_file->files().file_size(index));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue