added consts and minor refactor (#1137)

added consts and minor refactor
This commit is contained in:
Alden Torres 2016-09-23 16:51:20 -04:00 committed by Arvid Norberg
parent 158ae3a4ba
commit b1b74657f6
6 changed files with 27 additions and 34 deletions

View File

@ -1989,7 +1989,7 @@ namespace libtorrent
, std::function<void(disk_io_job const*)> handler) , std::function<void(disk_io_job const*)> handler)
{ {
disk_io_job* j = allocate_job(disk_io_job::load_torrent); disk_io_job* j = allocate_job(disk_io_job::load_torrent);
j->requester = reinterpret_cast<char*>(params); j->requester = reinterpret_cast<void*>(params);
j->callback = std::move(handler); j->callback = std::move(handler);
add_job(j); add_job(j);

View File

@ -362,7 +362,7 @@ namespace libtorrent
#endif #endif
void stat_file(std::string const& inf, file_status* s void stat_file(std::string const& inf, file_status* s
, error_code& ec, int flags) , error_code& ec, int const flags)
{ {
ec.clear(); ec.clear();
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS

View File

@ -4535,7 +4535,7 @@ namespace aux {
} }
} }
void session_impl::post_torrent_updates(std::uint32_t flags) void session_impl::post_torrent_updates(std::uint32_t const flags)
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
@ -4557,10 +4557,8 @@ namespace aux {
// pushed back. Perhaps the status_update_alert could even have a fixed // pushed back. Perhaps the status_update_alert could even have a fixed
// array of n entries rather than a vector, to further improve memory // array of n entries rather than a vector, to further improve memory
// locality. // locality.
for (std::vector<torrent*>::iterator i = state_updates.begin() for (auto& t : state_updates)
, end(state_updates.end()); i != end; ++i)
{ {
torrent* t = *i;
TORRENT_ASSERT(t->m_links[aux::session_impl::torrent_state_updates].in_list()); TORRENT_ASSERT(t->m_links[aux::session_impl::torrent_state_updates].in_list());
status.push_back(torrent_status()); status.push_back(torrent_status());
// querying accurate download counters may require // querying accurate download counters may require
@ -4649,25 +4647,25 @@ namespace aux {
} }
error_code ec; error_code ec;
torrent_handle handle = add_torrent(*params, ec); add_torrent(*params, ec);
delete params; delete params;
} }
void session_impl::on_async_load_torrent(disk_io_job const* j) void session_impl::on_async_load_torrent(disk_io_job const* j)
{ {
add_torrent_params* params = static_cast<add_torrent_params*>(j->requester); add_torrent_params* params = reinterpret_cast<add_torrent_params*>(j->requester);
error_code ec;
torrent_handle handle;
if (j->error.ec) if (j->error.ec)
{ {
ec = j->error.ec; m_alerts.emplace_alert<add_torrent_alert>(torrent_handle()
m_alerts.emplace_alert<add_torrent_alert>(handle, *params, ec); , *params, j->error.ec);
} }
else else
{ {
params->url.clear(); params->url.clear();
params->ti = std::shared_ptr<torrent_info>(j->buffer.torrent_file); params->ti = std::shared_ptr<torrent_info>(j->buffer.torrent_file);
handle = add_torrent(*params, ec);
error_code ec;
add_torrent(*params, ec);
} }
delete params; delete params;

View File

@ -52,7 +52,7 @@ namespace libtorrent
m_stat_cache[i].file_size = size; m_stat_cache[i].file_size = size;
} }
void stat_cache::set_error(int i, error_code const& ec) void stat_cache::set_error(int const i, error_code const& ec)
{ {
TORRENT_ASSERT(i >= 0); TORRENT_ASSERT(i >= 0);
if (i >= int(m_stat_cache.size())) if (i >= int(m_stat_cache.size()))
@ -62,14 +62,14 @@ namespace libtorrent
m_stat_cache[i].file_size = file_error - error_index; m_stat_cache[i].file_size = file_error - error_index;
} }
void stat_cache::set_dirty(int i) void stat_cache::set_dirty(int const i)
{ {
TORRENT_ASSERT(i >= 0); TORRENT_ASSERT(i >= 0);
if (i >= int(m_stat_cache.size())) return; if (i >= int(m_stat_cache.size())) return;
m_stat_cache[i].file_size = not_in_cache; m_stat_cache[i].file_size = not_in_cache;
} }
std::int64_t stat_cache::get_filesize(int i, file_storage const& fs std::int64_t stat_cache::get_filesize(int const i, file_storage const& fs
, std::string const& save_path, error_code& ec) , std::string const& save_path, error_code& ec)
{ {
TORRENT_ASSERT(i < int(fs.num_files())); TORRENT_ASSERT(i < int(fs.num_files()));
@ -84,7 +84,7 @@ namespace libtorrent
{ {
// query the filesystem // query the filesystem
file_status s; file_status s;
std::string file_path = fs.file_path(i, save_path); std::string const file_path = fs.file_path(i, save_path);
stat_file(file_path, &s, ec); stat_file(file_path, &s, ec);
if (ec) if (ec)
{ {

View File

@ -610,7 +610,7 @@ namespace libtorrent
for (int i = 0; i < files().num_files(); ++i) for (int i = 0; i < files().num_files(); ++i)
{ {
std::int64_t sz = m_stat_cache.get_filesize( std::int64_t const sz = m_stat_cache.get_filesize(
i, files(), m_save_path, ec.ec); i, files(), m_save_path, ec.ec);
if (sz < 0) if (sz < 0)
@ -645,7 +645,7 @@ namespace libtorrent
return false; return false;
} }
void default_storage::rename_file(int index, std::string const& new_filename void default_storage::rename_file(int const index, std::string const& new_filename
, storage_error& ec) , storage_error& ec)
{ {
if (index < 0 || index >= files().num_files()) return; if (index < 0 || index >= files().num_files()) return;
@ -1498,11 +1498,10 @@ namespace libtorrent
int piece_manager::check_no_fastresume(storage_error& ec) int piece_manager::check_no_fastresume(storage_error& ec)
{ {
bool has_files = false;
if (!m_storage->settings().get_bool(settings_pack::no_recheck_incomplete_resume)) if (!m_storage->settings().get_bool(settings_pack::no_recheck_incomplete_resume))
{ {
storage_error se; storage_error se;
has_files = m_storage->has_any_file(se); bool const has_files = m_storage->has_any_file(se);
if (se) if (se)
{ {

View File

@ -625,7 +625,7 @@ namespace libtorrent
if (should_log()) if (should_log())
{ {
debug_log("creating torrent: %s max-uploads: %d max-connections: %d " debug_log("creating torrent: %s max-uploads: %d max-connections: %d "
"upload-limit: %d download-limit: %d flags: %s%s%s%s%s%s%s%s%s%s%s" "upload-limit: %d download-limit: %d flags: %s%s%s%s%s%s%s%s%s%s%s "
"save-path: %s" "save-path: %s"
, torrent_file().name().c_str() , torrent_file().name().c_str()
, p.max_uploads , p.max_uploads
@ -1248,10 +1248,9 @@ namespace libtorrent
update_gauge(); update_gauge();
for (peer_iterator i = m_connections.begin() for (auto const& p : m_connections)
, end(m_connections.end()); i != end; ++i)
{ {
peer_has((*i)->get_bitfield(), *i); peer_has(p->get_bitfield(), p);
} }
} }
@ -2298,12 +2297,10 @@ namespace libtorrent
int const num_blocks_per_piece = torrent_file().piece_length() / block_size(); int const num_blocks_per_piece = torrent_file().piece_length() / block_size();
for (std::map<int, bitfield>::const_iterator i for (auto const& p : m_add_torrent_params->unfinished_pieces)
= m_add_torrent_params->unfinished_pieces.begin()
, end(m_add_torrent_params->unfinished_pieces.end()); i != end; ++i)
{ {
int const piece = i->first; int const piece = p.first;
bitfield const& blocks = i->second; bitfield const& blocks = p.second;
if (piece < 0 || piece > torrent_file().num_pieces()) continue; if (piece < 0 || piece > torrent_file().num_pieces()) continue;
@ -7881,9 +7878,8 @@ namespace libtorrent
} }
else else
{ {
for (std::vector<announce_entry>::iterator i = m_trackers.begin() for (auto& t : m_trackers)
, end(m_trackers.end()); i != end; ++i) t.complete_sent = true;
i->complete_sent = true;
if (m_state != torrent_status::finished if (m_state != torrent_status::finished
&& m_state != torrent_status::seeding) && m_state != torrent_status::seeding)
@ -10856,7 +10852,7 @@ namespace libtorrent
} }
} }
void torrent::set_state(torrent_status::state_t s) void torrent::set_state(torrent_status::state_t const s)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(s != 0); // this state isn't used anymore TORRENT_ASSERT(s != 0); // this state isn't used anymore