From b1b74657f69a97cc1721864765a28a5e8c36c647 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 23 Sep 2016 16:51:20 -0400 Subject: [PATCH] added consts and minor refactor (#1137) added consts and minor refactor --- src/disk_io_thread.cpp | 2 +- src/file.cpp | 2 +- src/session_impl.cpp | 20 +++++++++----------- src/stat_cache.cpp | 8 ++++---- src/storage.cpp | 7 +++---- src/torrent.cpp | 22 +++++++++------------- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 369f95ffe..615c96bb7 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1989,7 +1989,7 @@ namespace libtorrent , std::function handler) { disk_io_job* j = allocate_job(disk_io_job::load_torrent); - j->requester = reinterpret_cast(params); + j->requester = reinterpret_cast(params); j->callback = std::move(handler); add_job(j); diff --git a/src/file.cpp b/src/file.cpp index 0b43c3dd7..91f7ae70c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -362,7 +362,7 @@ namespace libtorrent #endif void stat_file(std::string const& inf, file_status* s - , error_code& ec, int flags) + , error_code& ec, int const flags) { ec.clear(); #ifdef TORRENT_WINDOWS diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 6210abaf3..fd3a08387 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -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; @@ -4557,10 +4557,8 @@ namespace aux { // pushed back. Perhaps the status_update_alert could even have a fixed // array of n entries rather than a vector, to further improve memory // locality. - for (std::vector::iterator i = state_updates.begin() - , end(state_updates.end()); i != end; ++i) + for (auto& t : state_updates) { - torrent* t = *i; TORRENT_ASSERT(t->m_links[aux::session_impl::torrent_state_updates].in_list()); status.push_back(torrent_status()); // querying accurate download counters may require @@ -4649,25 +4647,25 @@ namespace aux { } error_code ec; - torrent_handle handle = add_torrent(*params, ec); + add_torrent(*params, ec); delete params; } void session_impl::on_async_load_torrent(disk_io_job const* j) { - add_torrent_params* params = static_cast(j->requester); - error_code ec; - torrent_handle handle; + add_torrent_params* params = reinterpret_cast(j->requester); if (j->error.ec) { - ec = j->error.ec; - m_alerts.emplace_alert(handle, *params, ec); + m_alerts.emplace_alert(torrent_handle() + , *params, j->error.ec); } else { params->url.clear(); params->ti = std::shared_ptr(j->buffer.torrent_file); - handle = add_torrent(*params, ec); + + error_code ec; + add_torrent(*params, ec); } delete params; diff --git a/src/stat_cache.cpp b/src/stat_cache.cpp index dc1a25d90..9eb042415 100644 --- a/src/stat_cache.cpp +++ b/src/stat_cache.cpp @@ -52,7 +52,7 @@ namespace libtorrent 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); if (i >= int(m_stat_cache.size())) @@ -62,14 +62,14 @@ namespace libtorrent 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); if (i >= int(m_stat_cache.size())) return; 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) { TORRENT_ASSERT(i < int(fs.num_files())); @@ -84,7 +84,7 @@ namespace libtorrent { // query the filesystem 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); if (ec) { diff --git a/src/storage.cpp b/src/storage.cpp index f0c23ebe2..89a85eb74 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -610,7 +610,7 @@ namespace libtorrent 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); if (sz < 0) @@ -645,7 +645,7 @@ namespace libtorrent 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) { if (index < 0 || index >= files().num_files()) return; @@ -1498,11 +1498,10 @@ namespace libtorrent 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)) { storage_error se; - has_files = m_storage->has_any_file(se); + bool const has_files = m_storage->has_any_file(se); if (se) { diff --git a/src/torrent.cpp b/src/torrent.cpp index 0f88b55bb..e4fa1d28a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -625,7 +625,7 @@ namespace libtorrent if (should_log()) { 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" , torrent_file().name().c_str() , p.max_uploads @@ -1248,10 +1248,9 @@ namespace libtorrent update_gauge(); - for (peer_iterator i = m_connections.begin() - , end(m_connections.end()); i != end; ++i) + for (auto const& p : m_connections) { - 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(); - for (std::map::const_iterator i - = m_add_torrent_params->unfinished_pieces.begin() - , end(m_add_torrent_params->unfinished_pieces.end()); i != end; ++i) + for (auto const& p : m_add_torrent_params->unfinished_pieces) { - int const piece = i->first; - bitfield const& blocks = i->second; + int const piece = p.first; + bitfield const& blocks = p.second; if (piece < 0 || piece > torrent_file().num_pieces()) continue; @@ -7881,9 +7878,8 @@ namespace libtorrent } else { - for (std::vector::iterator i = m_trackers.begin() - , end(m_trackers.end()); i != end; ++i) - i->complete_sent = true; + for (auto& t : m_trackers) + t.complete_sent = true; if (m_state != torrent_status::finished && 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(s != 0); // this state isn't used anymore