1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-22 07:42:37 +00:00

perf: avoid heap allocations in daemon::printMessage() (#5724)

This commit is contained in:
Charles Kerr 2023-07-04 12:00:46 -05:00 committed by GitHub
parent e68b76bc14
commit 0bb222b2cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -311,14 +311,22 @@ static void printMessage(
std::string_view filename, std::string_view filename,
long line) long line)
{ {
auto const out = std::empty(name) ? fmt::format(FMT_STRING("{:s} ({:s}:{:d})"), message, filename, line) : auto out = tr_strbuf<char, 2048U>{};
fmt::format(FMT_STRING("{:s} {:s} ({:s}:{:d})"), name, message, filename, line);
if (std::empty(name))
{
fmt::format_to(std::back_inserter(out), "{:s} ({:s}:{:d})", message, filename, line);
}
else
{
fmt::format_to(std::back_inserter(out), "{:s} {:s} ({:s}:{:d})", name, message, filename, line);
}
if (file != TR_BAD_SYS_FILE) if (file != TR_BAD_SYS_FILE)
{ {
auto timestr = std::array<char, 64>{}; auto timestr = std::array<char, 64>{};
tr_logGetTimeStr(std::data(timestr), std::size(timestr)); tr_logGetTimeStr(std::data(timestr), std::size(timestr));
tr_sys_file_write_line(file, fmt::format(FMT_STRING("[{:s}] {:s} {:s}"), std::data(timestr), levelName(level), out)); tr_sys_file_write_line(file, fmt::format("[{:s}] {:s} {:s}", std::data(timestr), levelName(level), std::data(out)));
} }
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG