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:
parent
e68b76bc14
commit
0bb222b2cb
1 changed files with 11 additions and 3 deletions
|
@ -311,14 +311,22 @@ static void printMessage(
|
|||
std::string_view filename,
|
||||
long line)
|
||||
{
|
||||
auto const out = std::empty(name) ? fmt::format(FMT_STRING("{:s} ({:s}:{:d})"), message, filename, line) :
|
||||
fmt::format(FMT_STRING("{:s} {:s} ({:s}:{:d})"), name, message, filename, line);
|
||||
auto out = tr_strbuf<char, 2048U>{};
|
||||
|
||||
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)
|
||||
{
|
||||
auto timestr = std::array<char, 64>{};
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue