From 28f096e94eeba83b68b32d2436b230093b0eeef3 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 30 Nov 2017 18:57:48 -0500 Subject: [PATCH] added const to static arrays, minor refactor in alert.cpp --- include/libtorrent/alert_types.hpp | 2 +- src/alert.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 7e07ffa04..7409f1c72 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2474,7 +2474,7 @@ namespace libtorrent { private: std::reference_wrapper m_alloc; aux::allocation_slot m_msg_idx; - int const m_size; + std::size_t const m_size; #ifndef TORRENT_NO_DEPRECATE public: direction_t TORRENT_DEPRECATED_MEMBER dir; diff --git a/src/alert.cpp b/src/alert.cpp index cc66ca7d1..6272d64cc 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -271,7 +271,7 @@ namespace libtorrent { std::string performance_alert::message() const { - static char const* warning_str[] = + static char const* const warning_str[] = { "max outstanding disk writes reached", "max outstanding piece requests reached", @@ -301,7 +301,7 @@ namespace libtorrent { std::string state_changed_alert::message() const { - static char const* state_str[] = + static char const* const state_str[] = {"checking (q)", "checking", "dl metadata" , "downloading", "finished", "seeding", "allocating" , "checking (r)"}; @@ -459,8 +459,8 @@ namespace libtorrent { std::string tracker_announce_alert::message() const { - static const char* event_str[] = {"none", "completed", "started", "stopped", "paused"}; - TORRENT_ASSERT_VAL(event < int(sizeof(event_str)/sizeof(event_str[0])), event); + static const char* const event_str[] = {"none", "completed", "started", "stopped", "paused"}; + TORRENT_ASSERT_VAL(event < int(sizeof(event_str) / sizeof(event_str[0])), event); return tracker_alert::message() + " sending announce (" + event_str[event] + ")"; } @@ -806,7 +806,7 @@ namespace { char const* sock_type_str(socket_type_t type) { - static char const* type_str[] = + static char const* const type_str[] = { "TCP", "TCP/SSL", "UDP", "I2P", "Socks5", "uTP/SSL" }; return type_str[sock_type_idx(type)]; @@ -1176,7 +1176,7 @@ namespace { std::string peer_blocked_alert::message() const { char ret[600]; - static char const* reason_str[] = + static char const* const reason_str[] = { "ip_filter", "port_filter", @@ -1295,7 +1295,7 @@ namespace { std::string anonymous_mode_alert::message() const { char msg[200]; - static char const* msgs[] = { + static char const* const msgs[] = { "tracker is not anonymous, set a proxy" }; std::snprintf(msg, sizeof(msg), "%s: %s: %s" @@ -1505,7 +1505,7 @@ namespace { char const* operation_name(operation_t const op) { - static char const* names[] = { + static char const* const names[] = { "unknown", "bittorrent", "iocontrol", @@ -1548,7 +1548,7 @@ namespace { }; int const idx = static_cast(op); - if (idx < 0 || idx >= int(sizeof(names)/sizeof(names[0]))) + if (idx < 0 || idx >= int(sizeof(names) / sizeof(names[0]))) return "unknown operation"; return names[idx]; @@ -1844,7 +1844,7 @@ namespace { std::string peer_log_alert::message() const { - static char const* mode[] = + static char const* const mode[] = { "<==", "==>", "<<<", ">>>", "***" }; return torrent_alert::message() + " [" + print_endpoint(endpoint) + "] " + mode[direction] + " " + event_type + " [ " + log_message() + " ]"; @@ -2029,10 +2029,10 @@ namespace { , span buf, dht_pkt_alert::direction_t d , udp::endpoint const& ep) : direction(d) - , node(std::move(ep)) + , node(ep) , m_alloc(alloc) , m_msg_idx(alloc.copy_buffer(buf)) - , m_size(int(buf.size())) + , m_size(buf.size()) #ifndef TORRENT_NO_DEPRECATE , dir(d) #endif @@ -2040,7 +2040,7 @@ namespace { span dht_pkt_alert::pkt_buf() const { - return {m_alloc.get().ptr(m_msg_idx), std::size_t(m_size)}; + return {m_alloc.get().ptr(m_msg_idx), m_size}; } std::string dht_pkt_alert::message() const @@ -2055,7 +2055,7 @@ namespace { std::string msg = print_entry(print, true); - char const* prefix[2] = { "<==", "==>"}; + static char const* const prefix[2] = {"<==", "==>"}; char buf[1024]; std::snprintf(buf, sizeof(buf), "%s [%s] %s", prefix[direction] , print_endpoint(node).c_str(), msg.c_str());