silence msvc performance warnings. introduce more override and finals

This commit is contained in:
arvidn 2015-11-19 23:37:45 -05:00
parent c9c5496f1c
commit 4aaa8ca4a9
9 changed files with 117 additions and 77 deletions

View File

@ -26,8 +26,12 @@
#include "gil.hpp"
#include "bytes.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/python.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
using namespace boost::python;
using namespace libtorrent;
namespace lt = libtorrent;

View File

@ -2,8 +2,13 @@
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/time.hpp"

View File

@ -105,6 +105,7 @@ namespace libtorrent
std::string get_symlink_path(std::string const& p)
{
#if defined TORRENT_WINDOWS
TORRENT_UNUSED(p);
return "";
#else
std::string path = convert_to_native(p);
@ -361,7 +362,7 @@ namespace libtorrent
#endif
m_files.set_piece_length(piece_size);
if (flags & (optimize_alignment | mutable_torrent_support))
m_files.optimize(pad_file_limit, alignment, flags & mutable_torrent_support);
m_files.optimize(pad_file_limit, alignment, (flags & mutable_torrent_support) != 0);
m_files.set_num_pieces(static_cast<int>(
(m_files.total_size() + m_files.piece_length() - 1) / m_files.piece_length()));

View File

@ -97,7 +97,8 @@ namespace libtorrent { namespace
return ret;
}
struct metadata_plugin : torrent_plugin
struct metadata_plugin TORRENT_FINAL
: torrent_plugin
{
metadata_plugin(torrent& t)
: m_torrent(t)
@ -111,19 +112,19 @@ namespace libtorrent { namespace
bool need_loaded()
{ return m_torrent.need_loaded(); }
*/
virtual void on_unload()
virtual void on_unload() TORRENT_OVERRIDE
{
m_metadata.reset();
}
virtual void on_load()
virtual void on_load() TORRENT_OVERRIDE
{
// initialize m_metadata_size
TORRENT_ASSERT(m_torrent.is_loaded());
metadata();
}
virtual void on_files_checked()
virtual void on_files_checked() TORRENT_OVERRIDE
{
// if the torrent is a seed, make a reference to
// the metadata from the torrent before it is deallocated
@ -131,7 +132,7 @@ namespace libtorrent { namespace
}
virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle const& pc);
peer_connection_handle const& pc) TORRENT_OVERRIDE;
buffer::const_interval metadata() const
{
@ -251,10 +252,13 @@ namespace libtorrent { namespace
// this vector keeps track of how many times each meatdata
// block has been requested
std::vector<int> m_requested_metadata;
// explicitly disallow assignment, to silence msvc warning
metadata_plugin& operator=(metadata_plugin const&);
};
struct metadata_peer_plugin : peer_plugin
struct metadata_peer_plugin TORRENT_FINAL
: peer_plugin
{
metadata_peer_plugin(torrent& t, peer_connection& pc
, metadata_plugin& tp)
@ -268,17 +272,17 @@ namespace libtorrent { namespace
, m_tp(tp)
{}
virtual char const* type() const { return "LT_metadata"; }
virtual char const* type() const TORRENT_OVERRIDE { return "LT_metadata"; }
// can add entries to the extension handshake
virtual void add_handshake(entry& h)
virtual void add_handshake(entry& h) TORRENT_OVERRIDE
{
entry& messages = h["m"];
messages["LT_metadata"] = 14;
}
// called when the extension handshake from the other end is received
virtual bool on_extension_handshake(bdecode_node const& h)
virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE
{
m_message_index = 0;
if (h.type() != bdecode_node::dict_t) return false;
@ -385,7 +389,7 @@ namespace libtorrent { namespace
}
virtual bool on_extended(int length
, int msg, buffer::const_interval body)
, int msg, buffer::const_interval body) TORRENT_OVERRIDE
{
if (msg != 14) return false;
if (m_message_index == 0) return false;
@ -487,7 +491,7 @@ namespace libtorrent { namespace
return true;
}
virtual void tick()
virtual void tick() TORRENT_OVERRIDE
{
if (m_pc.is_disconnecting()) return;
@ -518,7 +522,7 @@ namespace libtorrent { namespace
// request to this peer, and reset to false when
// we receive a reply to our request.
bool m_waiting_metadata_request;
// this is the message index the remote peer uses
// for metadata extension messages.
int m_message_index;
@ -545,6 +549,9 @@ namespace libtorrent { namespace
torrent& m_torrent;
peer_connection& m_pc;
metadata_plugin& m_tp;
// explicitly disallow assignment, to silence msvc warning
metadata_peer_plugin& operator=(metadata_peer_plugin const&);
};
boost::shared_ptr<peer_plugin> metadata_plugin::new_connection(

View File

@ -118,7 +118,9 @@ namespace libtorrent {
namespace
{
struct smart_ban_plugin : torrent_plugin, boost::enable_shared_from_this<smart_ban_plugin>
struct smart_ban_plugin TORRENT_FINAL
: torrent_plugin
, boost::enable_shared_from_this<smart_ban_plugin>
{
smart_ban_plugin(torrent& t)
: m_torrent(t)
@ -134,7 +136,7 @@ namespace
{ fclose(m_log_file); }
#endif
void on_piece_pass(int p)
virtual void on_piece_pass(int p) TORRENT_OVERRIDE
{
#ifndef TORRENT_DISABLE_LOGGING
m_torrent.debug_log(" PIECE PASS [ p: %d | block_hash_size: %d ]"
@ -186,7 +188,7 @@ namespace
}
}
void on_piece_failed(int p)
virtual void on_piece_failed(int p) TORRENT_OVERRIDE
{
// The piece failed the hash check. Record
// the CRC and origin peer of every block
@ -315,7 +317,7 @@ namespace
, print_address(p->ip().address()).c_str());
#endif
}
void on_read_ok_block(std::pair<piece_block, block_entry> b, address a, disk_io_job const* j)
{
TORRENT_ASSERT(m_torrent.session().is_single_thread());
@ -368,7 +370,7 @@ namespace
if (p->connection) p->connection->disconnect(
errors::peer_banned, op_bittorrent);
}
torrent& m_torrent;
// This table maps a piece_block (piece and block index
@ -385,6 +387,8 @@ namespace
#ifdef TORRENT_LOG_HASH_FAILURES
FILE* m_log_file;
#endif
// explicitly disallow assignment, to silence msvc warning
smart_ban_plugin& operator=(smart_ban_plugin const&);
};
} }

View File

@ -170,14 +170,14 @@ namespace libtorrent
, add_torrent_params const& p, int block_size)
: m_ses(ses)
, m_complete(0xffffff)
, m_upload_mode(p.flags & add_torrent_params::flag_upload_mode)
, m_upload_mode((p.flags & add_torrent_params::flag_upload_mode) != 0)
, m_connections_initialized(false)
, m_abort(false)
, m_allow_peers((p.flags & add_torrent_params::flag_paused) == 0)
, m_share_mode(p.flags & add_torrent_params::flag_share_mode)
, m_share_mode((p.flags & add_torrent_params::flag_share_mode) != 0)
, m_have_all(false)
, m_graceful_pause_mode(false)
, m_state_subscription(p.flags & add_torrent_params::flag_update_subscribe)
, m_state_subscription((p.flags & add_torrent_params::flag_update_subscribe) != 0)
, m_max_connections(0xffffff)
, m_block_size_shift(root2(block_size))
, m_state(torrent_status::checking_resume_data)
@ -237,7 +237,7 @@ namespace libtorrent
, m_got_tracker_response(false)
, m_seed_mode(false)
, m_super_seeding(false)
, m_override_resume_data(p.flags & add_torrent_params::flag_override_resume_data)
, m_override_resume_data((p.flags & add_torrent_params::flag_override_resume_data) != 0)
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
, m_resolving_country(false)
, m_resolve_countries(false)
@ -251,8 +251,8 @@ namespace libtorrent
, m_need_connect_boost(true)
, m_lsd_seq(0)
, m_magnet_link(false)
, m_apply_ip_filter(p.flags & add_torrent_params::flag_apply_ip_filter)
, m_merge_resume_trackers(p.flags & add_torrent_params::flag_merge_resume_trackers)
, m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0)
, m_merge_resume_trackers((p.flags & add_torrent_params::flag_merge_resume_trackers) != 0)
, m_padding(0)
, m_priority(0)
, m_incomplete(0xffffff)
@ -262,7 +262,7 @@ namespace libtorrent
, m_is_active_finished(false)
, m_ssl_torrent(false)
, m_deleted(false)
, m_pinned(p.flags & add_torrent_params::flag_pinned)
, m_pinned((p.flags & add_torrent_params::flag_pinned) != 0)
, m_should_be_loaded(true)
, m_last_download((std::numeric_limits<boost::int16_t>::min)())
, m_num_seeds(0)
@ -277,9 +277,9 @@ namespace libtorrent
, m_last_scrape((std::numeric_limits<boost::int16_t>::min)())
, m_progress_ppm(0)
, m_pending_active_change(false)
, m_use_resume_save_path(p.flags & add_torrent_params::flag_use_resume_save_path)
, m_merge_resume_http_seeds(p.flags & add_torrent_params::flag_merge_resume_http_seeds)
, m_stop_when_ready(p.flags & add_torrent_params::flag_stop_when_ready)
, m_use_resume_save_path((p.flags & add_torrent_params::flag_use_resume_save_path) != 0)
, m_merge_resume_http_seeds((p.flags & add_torrent_params::flag_merge_resume_http_seeds) != 0)
, m_stop_when_ready((p.flags & add_torrent_params::flag_stop_when_ready) != 0)
{
// we cannot log in the constructor, because it relies on shared_from_this
// being initialized, which happens after the constructor returns.
@ -331,7 +331,7 @@ namespace libtorrent
m_trackers = m_torrent_file->trackers();
if (m_torrent_file->is_valid())
{
m_seed_mode = p.flags & add_torrent_params::flag_seed_mode;
m_seed_mode = (p.flags & add_torrent_params::flag_seed_mode) != 0;
m_connections_initialized = true;
m_block_size_shift = root2((std::min)(block_size, m_torrent_file->piece_length()));
}
@ -3506,7 +3506,7 @@ namespace libtorrent
i != resp.peers4.end(); ++i)
{
tcp::endpoint a(address_v4(i->ip), i->port);
need_update |= bool(add_peer(a, peer_info::tracker));
need_update |= bool(add_peer(a, peer_info::tracker) != NULL);
}
#if TORRENT_USE_IPV6
@ -3514,7 +3514,7 @@ namespace libtorrent
i != resp.peers6.end(); ++i)
{
tcp::endpoint a(address_v6(i->ip), i->port);
need_update |= bool(add_peer(a, peer_info::tracker));
need_update |= bool(add_peer(a, peer_info::tracker) != NULL);
}
#endif
if (need_update) state_updated();
@ -6774,27 +6774,27 @@ namespace libtorrent
if (seed_mode_ != -1) m_seed_mode = seed_mode_ && m_torrent_file->is_valid();
int super_seeding_ = rd.dict_find_int_value("super_seeding", -1);
if (super_seeding_ != -1) super_seeding(super_seeding_);
if (super_seeding_ != -1) super_seeding(super_seeding_ != 0);
int auto_managed_ = rd.dict_find_int_value("auto_managed", -1);
if (auto_managed_ != -1)
{
m_auto_managed = auto_managed_;
m_auto_managed = auto_managed_ != 0;
update_want_scrape();
update_state_list();
}
int sequential_ = rd.dict_find_int_value("sequential_download", -1);
if (sequential_ != -1) set_sequential_download(sequential_);
if (sequential_ != -1) set_sequential_download(sequential_ != 0);
int paused_ = rd.dict_find_int_value("paused", -1);
if (paused_ != -1)
{
set_allow_peers(!paused_);
m_announce_to_dht = !paused_;
m_announce_to_trackers = !paused_;
m_announce_to_lsd = !paused_;
set_allow_peers(paused_ == 0);
m_announce_to_dht = (paused_ == 0);
m_announce_to_trackers = (paused_ == 0);
m_announce_to_lsd = (paused_ == 0);
update_gauge();
update_want_peers();
@ -6802,11 +6802,11 @@ namespace libtorrent
update_state_list();
}
int dht_ = rd.dict_find_int_value("announce_to_dht", -1);
if (dht_ != -1) m_announce_to_dht = dht_;
if (dht_ != -1) m_announce_to_dht = (dht_ != 0);
int lsd_ = rd.dict_find_int_value("announce_to_lsd", -1);
if (lsd_ != -1) m_announce_to_lsd = lsd_;
if (lsd_ != -1) m_announce_to_lsd = (lsd_ != 0);
int track_ = rd.dict_find_int_value("announce_to_trackers", -1);
if (track_ != -1) m_announce_to_trackers = track_;
if (track_ != -1) m_announce_to_trackers = (track_ != 0);
#ifndef TORRENT_DISABLE_LOGGING
debug_log("loaded resume data: max-uploads: %d max-connections: %d "
@ -7707,7 +7707,7 @@ namespace libtorrent
if (m_share_mode)
recalc_share_mode();
return peerinfo->connection;
return peerinfo->connection != NULL;
}
bool torrent::set_metadata(char const* metadata_buf, int metadata_size)
@ -11853,7 +11853,7 @@ namespace libtorrent
st->is_finished = is_finished();
st->super_seeding = m_super_seeding;
st->has_metadata = valid_metadata();
bytes_done(*st, flags & torrent_handle::query_accurate_download_counters);
bytes_done(*st, (flags & torrent_handle::query_accurate_download_counters) != 0);
TORRENT_ASSERT(st->total_wanted_done >= 0);
TORRENT_ASSERT(st->total_done >= st->total_wanted_done);

View File

@ -1090,7 +1090,7 @@ namespace libtorrent
m_orig_files.reset(new file_storage(m_files));
}
#define SWAP(a, b) \
#define SWAP(tmp, a, b) \
tmp = a; \
a = b; \
b = tmp;
@ -1109,16 +1109,19 @@ namespace libtorrent
swap(m_creation_date, ti.m_creation_date);
m_comment.swap(ti.m_comment);
m_created_by.swap(ti.m_created_by);
boost::uint32_t tmp;
SWAP(m_multifile, ti.m_multifile);
SWAP(m_private, ti.m_private);
SWAP(m_i2p, ti.m_i2p);
swap(m_info_section, ti.m_info_section);
SWAP(m_info_section_size, ti.m_info_section_size);
swap(m_piece_hashes, ti.m_piece_hashes);
m_info_dict.swap(ti.m_info_dict);
swap(m_merkle_tree, ti.m_merkle_tree);
SWAP(m_merkle_first_leaf, ti.m_merkle_first_leaf);
std::swap(m_info_section_size, ti.m_info_section_size);
boost::uint32_t tmp;
SWAP(tmp, m_merkle_first_leaf, ti.m_merkle_first_leaf);
bool tmp2;
SWAP(tmp2, m_private, ti.m_private);
SWAP(tmp2, m_i2p, ti.m_i2p);
SWAP(tmp2, m_multifile, ti.m_multifile);
}
#undef SWAP

View File

@ -90,7 +90,8 @@ namespace libtorrent { namespace
struct ut_metadata_peer_plugin;
struct ut_metadata_plugin : torrent_plugin
struct ut_metadata_plugin TORRENT_FINAL
: torrent_plugin
{
ut_metadata_plugin(torrent& t)
: m_torrent(t)
@ -105,19 +106,19 @@ namespace libtorrent { namespace
bool need_loaded()
{ return m_torrent.need_loaded(); }
virtual void on_unload()
virtual void on_unload() TORRENT_OVERRIDE
{
m_metadata.reset();
}
virtual void on_load()
virtual void on_load() TORRENT_OVERRIDE
{
// initialize m_metadata_size
TORRENT_ASSERT(m_torrent.is_loaded());
metadata();
}
virtual void on_files_checked()
virtual void on_files_checked() TORRENT_OVERRIDE
{
// TODO: 2 if we were to initialize m_metadata_size lazily instead,
// we would probably be more efficient
@ -126,7 +127,7 @@ namespace libtorrent { namespace
}
virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle const& pc);
peer_connection_handle const& pc) TORRENT_OVERRIDE;
int get_metadata_size() const
{
@ -208,10 +209,14 @@ namespace libtorrent { namespace
// block has been requested and who we ended up getting it from
// std::numeric_limits<int>::max() means we have the piece
std::vector<metadata_piece> m_requested_metadata;
// explicitly disallow assignment, to silence msvc warning
ut_metadata_plugin& operator=(ut_metadata_plugin const&);
};
struct ut_metadata_peer_plugin : peer_plugin, boost::enable_shared_from_this<ut_metadata_peer_plugin>
struct ut_metadata_peer_plugin TORRENT_FINAL
: peer_plugin, boost::enable_shared_from_this<ut_metadata_peer_plugin>
{
friend struct ut_metadata_plugin;
@ -224,10 +229,10 @@ namespace libtorrent { namespace
, m_tp(tp)
{}
virtual char const* type() const { return "ut_metadata"; }
virtual char const* type() const TORRENT_OVERRIDE { return "ut_metadata"; }
// can add entries to the extension handshake
virtual void add_handshake(entry& h)
virtual void add_handshake(entry& h) TORRENT_OVERRIDE
{
entry& messages = h["m"];
messages["ut_metadata"] = 2;
@ -236,7 +241,7 @@ namespace libtorrent { namespace
}
// called when the extension handshake from the other end is received
virtual bool on_extension_handshake(bdecode_node const& h)
virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE
{
m_message_index = 0;
if (h.type() != bdecode_node::dict_t) return false;
@ -322,7 +327,7 @@ namespace libtorrent { namespace
}
virtual bool on_extended(int length
, int extended_msg, buffer::const_interval body)
, int extended_msg, buffer::const_interval body) TORRENT_OVERRIDE
{
if (extended_msg != 2) return false;
if (m_message_index == 0) return false;
@ -438,7 +443,7 @@ namespace libtorrent { namespace
return true;
}
virtual void tick()
virtual void tick() TORRENT_OVERRIDE
{
maybe_send_request();
while (!m_incoming_requests.empty()
@ -500,6 +505,9 @@ namespace libtorrent { namespace
torrent& m_torrent;
bt_peer_connection& m_pc;
ut_metadata_plugin& m_tp;
// explicitly disallow assignment, to silence msvc warning
ut_metadata_peer_plugin& operator=(ut_metadata_peer_plugin const&);
};
boost::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection(
@ -547,7 +555,7 @@ namespace libtorrent { namespace
return piece;
}
inline bool ut_metadata_plugin::received_metadata(
bool ut_metadata_plugin::received_metadata(
ut_metadata_peer_plugin& source
, char const* buf, int size, int piece, int total_size)
{

View File

@ -81,7 +81,8 @@ namespace libtorrent { namespace
return true;
}
struct ut_pex_plugin: torrent_plugin
struct ut_pex_plugin TORRENT_FINAL
: torrent_plugin
{
// randomize when we rebuild the pex message
// to evenly spread it out across all torrents
@ -91,8 +92,9 @@ namespace libtorrent { namespace
: m_torrent(t)
, m_last_msg(min_time())
, m_peers_in_message(0) {}
virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection_handle const& pc);
virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle const& pc) TORRENT_OVERRIDE;
std::vector<char>& get_ut_pex_msg()
{
@ -109,7 +111,7 @@ namespace libtorrent { namespace
// are calculated here and the pex message is created
// each peer connection will use this message
// max_peer_entries limits the packet size
virtual void tick()
virtual void tick() TORRENT_OVERRIDE
{
time_point now = aux::time_now();
if (now - seconds(60) < m_last_msg) return;
@ -231,11 +233,14 @@ namespace libtorrent { namespace
time_point m_last_msg;
std::vector<char> m_ut_pex_msg;
int m_peers_in_message;
// explicitly disallow assignment, to silence msvc warning
ut_pex_plugin& operator=(ut_pex_plugin const&);
};
struct ut_pex_peer_plugin : peer_plugin
{
struct ut_pex_peer_plugin TORRENT_FINAL
: peer_plugin
{
ut_pex_peer_plugin(torrent& t, peer_connection& pc, ut_pex_plugin& tp)
: m_torrent(t)
, m_pc(pc)
@ -251,15 +256,15 @@ namespace libtorrent { namespace
}
}
virtual char const* type() const { return "ut_pex"; }
virtual char const* type() const TORRENT_OVERRIDE { return "ut_pex"; }
virtual void add_handshake(entry& h)
virtual void add_handshake(entry& h) TORRENT_OVERRIDE
{
entry& messages = h["m"];
messages[extension_name] = extension_index;
}
virtual bool on_extension_handshake(bdecode_node const& h)
virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE
{
m_message_index = 0;
if (h.type() != bdecode_node::dict_t) return false;
@ -272,7 +277,7 @@ namespace libtorrent { namespace
return true;
}
virtual bool on_extended(int length, int msg, buffer::const_interval body)
virtual bool on_extended(int length, int msg, buffer::const_interval body) TORRENT_OVERRIDE
{
if (msg != extension_index) return false;
if (m_message_index == 0) return false;
@ -282,7 +287,7 @@ namespace libtorrent { namespace
m_pc.disconnect(errors::pex_message_too_large, op_bittorrent, 2);
return true;
}
if (body.left() < length) return true;
time_point now = aux::time_now();
@ -378,7 +383,7 @@ namespace libtorrent { namespace
peers6_t::value_type v(adr.address().to_v6().to_bytes(), adr.port());
peers6_t::iterator j = std::lower_bound(m_peers6.begin(), m_peers6.end(), v);
if (j != m_peers6.end() && *j == v) m_peers6.erase(j);
}
}
}
p6 = pex_msg.dict_find("added6");
@ -425,7 +430,7 @@ namespace libtorrent { namespace
// the peers second tick
// every minute we send a pex message
virtual void tick()
virtual void tick() TORRENT_OVERRIDE
{
// no handshake yet
if (!m_message_index) return;
@ -646,6 +651,9 @@ namespace libtorrent { namespace
// it is used to know if a diff message or a) ful
// message should be sent.
bool m_first_time;
// explicitly disallow assignment, to silence msvc warning
ut_pex_peer_plugin& operator=(ut_pex_peer_plugin const&);
};
boost::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection_handle const& pc)