0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 12:48:54 +02:00

ircd::server: Elide allocations for these stringifies.

This commit is contained in:
Jason Volk 2019-04-16 20:57:06 -07:00
parent 4038973297
commit 46acff07b7

View file

@ -849,12 +849,13 @@ ircd::server::peer::handle_open(link &link,
if(links.size() == 1) if(links.size() == 1)
err_set(eptr); err_set(eptr);
thread_local char rembuf[64];
log::derror log::derror
{ {
log, "peer(%p) link(%p) [%s]: open: %s", log, "peer(%p) link(%p) [%s]: open: %s",
this, this,
&link, &link,
string(remote), string(rembuf, remote),
what(eptr) what(eptr)
}; };
@ -875,13 +876,15 @@ void
ircd::server::peer::handle_close(link &link, ircd::server::peer::handle_close(link &link,
std::exception_ptr eptr) std::exception_ptr eptr)
{ {
thread_local char rembuf[64];
if(eptr) if(eptr)
log::derror log::derror
{ {
log, "peer(%p) link(%p) [%s]: close: %s", log, "peer(%p) link(%p) [%s]: close: %s",
this, this,
&link, &link,
string(remote), string(rembuf, remote),
what(eptr) what(eptr)
}; };
@ -912,6 +915,7 @@ ircd::server::peer::handle_error(link &link,
{ {
using std::errc; using std::errc;
using boost::asio::error::get_misc_category; using boost::asio::error::get_misc_category;
thread_local char rembuf[64];
const auto &ec{e.code()}; const auto &ec{e.code()};
if(system_category(ec)) switch(ec.value()) if(system_category(ec)) switch(ec.value())
@ -931,7 +935,7 @@ ircd::server::peer::handle_error(link &link,
log, "peer(%p) link(%p) [%s]: %s", log, "peer(%p) link(%p) [%s]: %s",
this, this,
&link, &link,
string(remote), string(rembuf, remote),
e.what() e.what()
}; };
@ -947,7 +951,7 @@ ircd::server::peer::handle_error(link &link,
log, "peer(%p) link(%p) [%s]: %s", log, "peer(%p) link(%p) [%s]: %s",
this, this,
&link, &link,
string(remote), string(rembuf, remote),
e.what() e.what()
}; };
@ -1037,12 +1041,13 @@ ircd::server::peer::handle_head_recv(const link &link,
// requests more effectively. // requests more effectively.
if(!server_version && head.server) if(!server_version && head.server)
{ {
thread_local char rembuf[64];
server_version = std::string{head.server}; server_version = std::string{head.server};
log::debug log::debug
{ {
log, "peer(%p) learned %s is '%s'", log, "peer(%p) learned %s is '%s'",
this, this,
string(remote), string(rembuf, remote),
server_version, server_version,
}; };
} }
@ -1107,6 +1112,7 @@ ircd::server::peer::del(link &link)
})); }));
assert(it != end(links)); assert(it != end(links));
thread_local char rembuf[64];
log::debug log::debug
{ {
log, "peer(%p) removing link(%p) %zu of %zu to %s", log, "peer(%p) removing link(%p) %zu of %zu to %s",
@ -1114,7 +1120,7 @@ ircd::server::peer::del(link &link)
&link, &link,
std::distance(begin(links), it), std::distance(begin(links), it),
links.size(), links.size(),
string(remote) string(rembuf, remote)
}; };
links.erase(it); links.erase(it);
@ -2186,6 +2192,7 @@ ircd::server::link::discard_read()
// Shouldn't ever be hit because the read() within discard() throws // Shouldn't ever be hit because the read() within discard() throws
// the pending error like an eof. // the pending error like an eof.
thread_local char rembuf[64];
const fmt::snstringf msg const fmt::snstringf msg
{ {
512, "peer(%p %s) link(%p q:%zu) socket(%s) discarded %zu of %zd unexpected bytes", 512, "peer(%p %s) link(%p q:%zu) socket(%s) discarded %zu of %zd unexpected bytes",
@ -2196,10 +2203,10 @@ ircd::server::link::discard_read()
this, this,
queue.size(), queue.size(),
likely(peer)? likely(peer)?
string(peer->remote): string(rembuf, peer->remote):
socket? socket?
string(remote_ipport(*socket)): string(rembuf, remote_ipport(*socket)):
std::string{}, string_view{},
discarded, discarded,
discard discard
}; };