use string_view in alert constructors (#1186)

This commit is contained in:
Arvid Norberg 2016-10-04 23:58:26 -04:00 committed by GitHub
parent 8d940a4013
commit 3c355bb3f8
3 changed files with 63 additions and 129 deletions

View File

@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/close_reason.hpp" #include "libtorrent/close_reason.hpp"
#include "libtorrent/piece_block.hpp" #include "libtorrent/piece_block.hpp"
#include "libtorrent/aux_/escape_string.hpp" // for convert_from_native #include "libtorrent/aux_/escape_string.hpp" // for convert_from_native
#include "libtorrent/string_view.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"
@ -129,7 +130,7 @@ namespace libtorrent
{ {
// internal // internal
tracker_alert(aux::stack_allocator& alloc, torrent_handle const& h tracker_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u); , string_view u);
static const int alert_type = 2; static const int alert_type = 2;
static const int static_category = alert::tracker_notification; static const int static_category = alert::tracker_notification;
@ -248,8 +249,7 @@ namespace libtorrent
{ {
// internal // internal
file_renamed_alert(aux::stack_allocator& alloc, torrent_handle const& h file_renamed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& n , string_view n, int idx);
, int idx);
TORRENT_DEFINE_ALERT_PRIO(file_renamed_alert, 7) TORRENT_DEFINE_ALERT_PRIO(file_renamed_alert, 7)
@ -419,12 +419,8 @@ namespace libtorrent
{ {
// internal // internal
tracker_error_alert(aux::stack_allocator& alloc tracker_error_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int times, int status, string_view u
, int times , error_code const& e, string_view m);
, int status
, std::string const& u
, error_code const& e
, std::string const& m);
TORRENT_DEFINE_ALERT(tracker_error_alert, 11) TORRENT_DEFINE_ALERT(tracker_error_alert, 11)
@ -452,9 +448,7 @@ namespace libtorrent
{ {
// internal // internal
tracker_warning_alert(aux::stack_allocator& alloc tracker_warning_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, string_view m);
, std::string const& u
, std::string const& m);
TORRENT_DEFINE_ALERT(tracker_warning_alert, 12) TORRENT_DEFINE_ALERT(tracker_warning_alert, 12)
@ -478,10 +472,7 @@ namespace libtorrent
{ {
// internal // internal
scrape_reply_alert(aux::stack_allocator& alloc scrape_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int incomp, int comp, string_view u);
, int incomp
, int comp
, std::string const& u);
TORRENT_DEFINE_ALERT(scrape_reply_alert, 13) TORRENT_DEFINE_ALERT(scrape_reply_alert, 13)
@ -500,13 +491,9 @@ namespace libtorrent
{ {
// internal // internal
scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, error_code const& e);
, std::string const& u
, error_code const& e);
scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, string_view m);
, std::string const& u
, std::string const& m);
TORRENT_DEFINE_ALERT(scrape_failed_alert, 14) TORRENT_DEFINE_ALERT(scrape_failed_alert, 14)
@ -538,9 +525,7 @@ namespace libtorrent
{ {
// internal // internal
tracker_reply_alert(aux::stack_allocator& alloc tracker_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int np, string_view u);
, int np
, std::string const& u);
TORRENT_DEFINE_ALERT(tracker_reply_alert, 15) TORRENT_DEFINE_ALERT(tracker_reply_alert, 15)
@ -578,7 +563,7 @@ namespace libtorrent
// internal // internal
tracker_announce_alert(aux::stack_allocator& alloc tracker_announce_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, std::string const& u, int e); , string_view u, int e);
TORRENT_DEFINE_ALERT(tracker_announce_alert, 17) TORRENT_DEFINE_ALERT(tracker_announce_alert, 17)
@ -883,7 +868,7 @@ namespace libtorrent
{ {
// internal // internal
storage_moved_alert(aux::stack_allocator& alloc storage_moved_alert(aux::stack_allocator& alloc
, torrent_handle const& h, std::string const& p); , torrent_handle const& h, string_view p);
TORRENT_DEFINE_ALERT(storage_moved_alert, 33) TORRENT_DEFINE_ALERT(storage_moved_alert, 33)
@ -907,9 +892,7 @@ namespace libtorrent
{ {
// internal // internal
storage_moved_failed_alert(aux::stack_allocator& alloc storage_moved_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, error_code const& e, string_view file
, error_code const& e
, std::string const& file
, char const* op); , char const* op);
TORRENT_DEFINE_ALERT(storage_moved_failed_alert, 34) TORRENT_DEFINE_ALERT(storage_moved_failed_alert, 34)
@ -1068,9 +1051,9 @@ namespace libtorrent
{ {
// internal // internal
url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u, error_code const& e); , string_view u, error_code const& e);
url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u, std::string const& m); , string_view u, string_view m);
TORRENT_DEFINE_ALERT(url_seed_alert, 42) TORRENT_DEFINE_ALERT(url_seed_alert, 42)
@ -1106,11 +1089,8 @@ namespace libtorrent
struct TORRENT_EXPORT file_error_alert final : torrent_alert struct TORRENT_EXPORT file_error_alert final : torrent_alert
{ {
// internal // internal
file_error_alert(aux::stack_allocator& alloc file_error_alert(aux::stack_allocator& alloc, error_code const& ec
, error_code const& ec , string_view file, char const* op, torrent_handle const& h);
, std::string const& file
, char const* op
, torrent_handle const& h);
TORRENT_DEFINE_ALERT(file_error_alert, 43) TORRENT_DEFINE_ALERT(file_error_alert, 43)
@ -1255,37 +1235,20 @@ namespace libtorrent
enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl }; enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl };
// internal // internal
listen_failed_alert( listen_failed_alert(aux::stack_allocator& alloc, string_view iface
aux::stack_allocator& alloc , libtorrent::address const& listen_addr, int listen_port
, std::string const& iface , int op, error_code const& ec, socket_type_t t);
, libtorrent::address const& listen_addr
, int listen_port listen_failed_alert(aux::stack_allocator& alloc, string_view iface
, int op , tcp::endpoint const& ep, int op, error_code const& ec
, error_code const& ec
, socket_type_t t); , socket_type_t t);
listen_failed_alert( listen_failed_alert(aux::stack_allocator& alloc, string_view iface
aux::stack_allocator& alloc , udp::endpoint const& ep, int op, error_code const& ec
, std::string const& iface
, tcp::endpoint const& ep
, int op
, error_code const& ec
, socket_type_t t); , socket_type_t t);
listen_failed_alert( listen_failed_alert(aux::stack_allocator& alloc, string_view iface
aux::stack_allocator& alloc , int op, error_code const& ec, socket_type_t t);
, std::string const& iface
, udp::endpoint const& ep
, int op
, error_code const& ec
, socket_type_t t);
listen_failed_alert(
aux::stack_allocator& alloc
, std::string const& iface
, int op
, error_code const& ec
, socket_type_t t);
TORRENT_DEFINE_ALERT_PRIO(listen_failed_alert, 48) TORRENT_DEFINE_ALERT_PRIO(listen_failed_alert, 48)
@ -1476,9 +1439,7 @@ namespace libtorrent
{ {
// internal // internal
fastresume_rejected_alert(aux::stack_allocator& alloc fastresume_rejected_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, error_code const& ec, string_view file
, error_code const& ec
, std::string const& file
, char const* op); , char const* op);
TORRENT_DEFINE_ALERT(fastresume_rejected_alert, 53) TORRENT_DEFINE_ALERT(fastresume_rejected_alert, 53)
@ -1649,7 +1610,7 @@ namespace libtorrent
{ {
// internal // internal
anonymous_mode_alert(aux::stack_allocator& alloc, torrent_handle const& h anonymous_mode_alert(aux::stack_allocator& alloc, torrent_handle const& h
, int k, std::string const& s); , int k, string_view s);
TORRENT_DEFINE_ALERT(anonymous_mode_alert, 59) TORRENT_DEFINE_ALERT(anonymous_mode_alert, 59)
@ -1690,8 +1651,7 @@ namespace libtorrent
{ {
// internal // internal
trackerid_alert(aux::stack_allocator& alloc, torrent_handle const& h trackerid_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u , string_view u, const std::string& id);
, const std::string& id);
TORRENT_DEFINE_ALERT(trackerid_alert, 61) TORRENT_DEFINE_ALERT(trackerid_alert, 61)
@ -1727,7 +1687,7 @@ namespace libtorrent
{ {
// internal // internal
torrent_error_alert(aux::stack_allocator& alloc, torrent_handle const& h torrent_error_alert(aux::stack_allocator& alloc, torrent_handle const& h
, error_code const& e, std::string const& f); , error_code const& e, string_view f);
TORRENT_DEFINE_ALERT(torrent_error_alert, 64) TORRENT_DEFINE_ALERT(torrent_error_alert, 64)
@ -1963,12 +1923,8 @@ namespace libtorrent
struct TORRENT_EXPORT dht_mutable_item_alert final : alert struct TORRENT_EXPORT dht_mutable_item_alert final : alert
{ {
dht_mutable_item_alert(aux::stack_allocator& alloc dht_mutable_item_alert(aux::stack_allocator& alloc
, std::array<char, 32> k , std::array<char, 32> k, std::array<char, 64> sig
, std::array<char, 64> sig , std::uint64_t sequence, string_view s, entry const& i, bool a);
, std::uint64_t sequence
, std::string const& s
, entry const& i
, bool a);
TORRENT_DEFINE_ALERT_PRIO(dht_mutable_item_alert, 75) TORRENT_DEFINE_ALERT_PRIO(dht_mutable_item_alert, 75)

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/span.hpp" #include "libtorrent/span.hpp"
#include "libtorrent/string_view.hpp"
#include <cstring> #include <cstring>
@ -48,11 +49,12 @@ namespace libtorrent { namespace aux
stack_allocator(stack_allocator const&) = delete; stack_allocator(stack_allocator const&) = delete;
stack_allocator& operator=(stack_allocator const&) = delete; stack_allocator& operator=(stack_allocator const&) = delete;
int copy_string(std::string const& str) int copy_string(string_view str)
{ {
int const ret = int(m_storage.size()); int const ret = int(m_storage.size());
m_storage.resize(ret + str.length() + 1); m_storage.resize(ret + str.size() + 1);
std::strcpy(&m_storage[ret], str.c_str()); std::memcpy(&m_storage[ret], str.data(), str.size());
m_storage[ret + str.length()] = '\0';
return ret; return ret;
} }

View File

@ -116,8 +116,7 @@ namespace libtorrent {
} }
tracker_alert::tracker_alert(aux::stack_allocator& alloc tracker_alert::tracker_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u)
, std::string const& u)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, url(u) , url(u)
@ -189,9 +188,7 @@ namespace libtorrent {
} }
file_renamed_alert::file_renamed_alert(aux::stack_allocator& alloc file_renamed_alert::file_renamed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view n, int const idx)
, std::string const& n
, int idx)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, name(n) , name(n)
@ -283,12 +280,8 @@ namespace libtorrent {
} }
tracker_error_alert::tracker_error_alert(aux::stack_allocator& alloc tracker_error_alert::tracker_error_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int times, int status, string_view u
, int times , error_code const& e, string_view m)
, int status
, std::string const& u
, error_code const& e
, std::string const& m)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
, times_in_row(times) , times_in_row(times)
, status_code(status) , status_code(status)
@ -321,9 +314,7 @@ namespace libtorrent {
} }
tracker_warning_alert::tracker_warning_alert(aux::stack_allocator& alloc tracker_warning_alert::tracker_warning_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, string_view m)
, std::string const& u
, std::string const& m)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, msg(m) , msg(m)
@ -348,10 +339,7 @@ namespace libtorrent {
} }
scrape_reply_alert::scrape_reply_alert(aux::stack_allocator& alloc scrape_reply_alert::scrape_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int incomp, int comp, string_view u)
, int incomp
, int comp
, std::string const& u)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
, incomplete(incomp) , incomplete(incomp)
, complete(comp) , complete(comp)
@ -368,9 +356,7 @@ namespace libtorrent {
} }
scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, error_code const& e)
, std::string const& u
, error_code const& e)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, msg(convert_from_native(e.message())) , msg(convert_from_native(e.message()))
@ -382,9 +368,7 @@ namespace libtorrent {
} }
scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, string_view m)
, std::string const& u
, std::string const& m)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, msg(m) , msg(m)
@ -411,9 +395,7 @@ namespace libtorrent {
} }
tracker_reply_alert::tracker_reply_alert(aux::stack_allocator& alloc tracker_reply_alert::tracker_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, int np, string_view u)
, int np
, std::string const& u)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
, num_peers(np) , num_peers(np)
{ {
@ -444,8 +426,7 @@ namespace libtorrent {
} }
tracker_announce_alert::tracker_announce_alert(aux::stack_allocator& alloc tracker_announce_alert::tracker_announce_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, string_view u, int e)
, std::string const& u, int e)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
, event(e) , event(e)
{ {
@ -656,7 +637,7 @@ namespace libtorrent {
} }
storage_moved_alert::storage_moved_alert(aux::stack_allocator& alloc storage_moved_alert::storage_moved_alert(aux::stack_allocator& alloc
, torrent_handle const& h, std::string const& p) , torrent_handle const& h, string_view p)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, path(p) , path(p)
@ -680,11 +661,8 @@ namespace libtorrent {
} }
storage_moved_failed_alert::storage_moved_failed_alert( storage_moved_failed_alert::storage_moved_failed_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc, torrent_handle const& h, error_code const& e
, torrent_handle const& h , string_view f, char const* op)
, error_code const& e
, std::string const& f
, char const* op)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
, error(e) , error(e)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -823,7 +801,7 @@ namespace libtorrent {
listen_failed_alert::listen_failed_alert( listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, std::string const& iface , string_view iface
, libtorrent::address const& listen_addr , libtorrent::address const& listen_addr
, int listen_port , int listen_port
, int op , int op
@ -843,7 +821,7 @@ namespace libtorrent {
listen_failed_alert::listen_failed_alert( listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, std::string const& iface , string_view iface
, tcp::endpoint const& ep , tcp::endpoint const& ep
, int op , int op
, error_code const& ec , error_code const& ec
@ -859,7 +837,7 @@ namespace libtorrent {
listen_failed_alert::listen_failed_alert( listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, std::string const& iface , string_view iface
, udp::endpoint const& ep , udp::endpoint const& ep
, int op , int op
, error_code const& ec , error_code const& ec
@ -875,7 +853,7 @@ namespace libtorrent {
listen_failed_alert::listen_failed_alert( listen_failed_alert::listen_failed_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, std::string const& iface , string_view iface
, int op , int op
, error_code const& ec , error_code const& ec
, socket_type_t t) , socket_type_t t)
@ -1059,7 +1037,7 @@ namespace libtorrent {
aux::stack_allocator& alloc aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, error_code const& ec , error_code const& ec
, std::string const& f , string_view f
, char const* op) , char const* op)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
, error(ec) , error(ec)
@ -1204,7 +1182,7 @@ namespace libtorrent {
: torrent_alert(alloc, h) {} : torrent_alert(alloc, h) {}
anonymous_mode_alert::anonymous_mode_alert(aux::stack_allocator& alloc anonymous_mode_alert::anonymous_mode_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int k, std::string const& s) , torrent_handle const& h, int k, string_view s)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
, kind(k) , kind(k)
, str(s) , str(s)
@ -1238,7 +1216,7 @@ namespace libtorrent {
trackerid_alert::trackerid_alert( trackerid_alert::trackerid_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, std::string const& u , string_view u
, const std::string& id) , const std::string& id)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, u)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -1272,7 +1250,7 @@ namespace libtorrent {
torrent_error_alert::torrent_error_alert( torrent_error_alert::torrent_error_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, error_code const& e, std::string const& f) , error_code const& e, string_view f)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
, error(e) , error(e)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -1550,7 +1528,7 @@ namespace libtorrent {
, std::array<char, 32> k , std::array<char, 32> k
, std::array<char, 64> sig , std::array<char, 64> sig
, std::uint64_t sequence , std::uint64_t sequence
, std::string const& s , string_view s
, entry const& i , entry const& i
, bool a) , bool a)
: key(k), signature(sig), seq(sequence), salt(s), item(i), authoritative(a) : key(k), signature(sig), seq(sequence), salt(s), item(i), authoritative(a)
@ -1756,7 +1734,7 @@ namespace libtorrent {
} }
url_seed_alert::url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h url_seed_alert::url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u, error_code const& e) , string_view u, error_code const& e)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, url(u) , url(u)
@ -1768,7 +1746,7 @@ namespace libtorrent {
{} {}
url_seed_alert::url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h url_seed_alert::url_seed_alert(aux::stack_allocator& alloc, torrent_handle const& h
, std::string const& u, std::string const& m) , string_view u, string_view m)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, url(u) , url(u)
@ -1800,9 +1778,7 @@ namespace libtorrent {
} }
file_error_alert::file_error_alert(aux::stack_allocator& alloc file_error_alert::file_error_alert(aux::stack_allocator& alloc
, error_code const& ec , error_code const& ec, string_view f, char const* op
, std::string const& f
, char const* op
, torrent_handle const& h) , torrent_handle const& h)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE