mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
perf: move log strings instead of cloning them (#5726)
This commit is contained in:
parent
0a6d1806f9
commit
6a2a4c3032
7 changed files with 34 additions and 31 deletions
|
@ -324,9 +324,9 @@ struct tau_tracker
|
|||
}
|
||||
else if (action == TAU_ACTION_ERROR)
|
||||
{
|
||||
std::string const errmsg = !std::empty(buf) ? buf.to_string() : _("Connection failed");
|
||||
logdbg(this->key, errmsg);
|
||||
std::string errmsg = !std::empty(buf) ? buf.to_string() : _("Connection failed");
|
||||
this->failAll(true, false, errmsg);
|
||||
logdbg(this->key, std::move(errmsg));
|
||||
}
|
||||
|
||||
this->upkeep();
|
||||
|
|
|
@ -771,7 +771,7 @@ void tr_logAddTrace_tier_announce_queue(tr_tier const* tier)
|
|||
fmt::format_to(std::back_inserter(buf), FMT_STRING("[{:d}:{:s}]"), i, tr_announce_event_get_string(events[i]));
|
||||
}
|
||||
|
||||
tr_logAddTraceTier(tier, buf);
|
||||
tr_logAddTraceTier(tier, std::move(buf));
|
||||
}
|
||||
|
||||
// higher priorities go to the front of the announce queue
|
||||
|
@ -876,7 +876,7 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e)
|
|||
{
|
||||
tr_logAddErrorTier(
|
||||
tier,
|
||||
fmt::format(_("Announce error: {error}"), fmt::arg("error", err)).append(fmt::format(" ({})", announce_url)));
|
||||
fmt::format(_("Announce error: {error} ({url})"), fmt::arg("error", err), fmt::arg("url", announce_url)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -886,12 +886,12 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e)
|
|||
tier,
|
||||
fmt::format(
|
||||
tr_ngettext(
|
||||
"Announce error: {error} (Retrying in {count} second)",
|
||||
"Announce error: {error} (Retrying in {count} seconds)",
|
||||
"Announce error: {error} (Retrying in {count} second) ({url})",
|
||||
"Announce error: {error} (Retrying in {count} seconds) ({url})",
|
||||
interval),
|
||||
fmt::arg("error", err),
|
||||
fmt::arg("count", interval))
|
||||
.append(fmt::format(" ({})", announce_url)));
|
||||
fmt::arg("count", interval),
|
||||
fmt::arg("url", announce_url)));
|
||||
tier_announce_event_push(tier, e, tr_time() + interval);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,14 +26,8 @@ bool tr_sys_file_write_line(tr_sys_file_t handle, std::string_view buffer, tr_er
|
|||
{
|
||||
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
||||
|
||||
bool ret = tr_sys_file_write(handle, std::data(buffer), std::size(buffer), nullptr, error);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
ret = tr_sys_file_write(handle, std::data(NativeEol), std::size(NativeEol), nullptr, error);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return tr_sys_file_write(handle, std::data(buffer), std::size(buffer), nullptr, error) &&
|
||||
tr_sys_file_write(handle, std::data(NativeEol), std::size(NativeEol), nullptr, error);
|
||||
}
|
||||
|
||||
std::vector<std::string> tr_sys_dir_get_files(
|
||||
|
|
|
@ -147,13 +147,13 @@ void readOrWriteBytes(
|
|||
if (!fd) // couldn't create/open it either
|
||||
{
|
||||
auto const err = errno;
|
||||
auto const msg = fmt::format(
|
||||
auto msg = fmt::format(
|
||||
_("Couldn't get '{path}': {error} ({error_code})"),
|
||||
fmt::arg("path", filename),
|
||||
fmt::arg("error", tr_strerror(err)),
|
||||
fmt::arg("error_code", err));
|
||||
tr_error_set(error, err, msg);
|
||||
tr_logAddErrorTor(tor, msg);
|
||||
tr_logAddErrorTor(tor, std::move(msg));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libtransmission/file.h"
|
||||
#include "libtransmission/log.h"
|
||||
#include "libtransmission/tr-assert.h"
|
||||
#include "libtransmission/tr-strbuf.h"
|
||||
#include "libtransmission/utils.h"
|
||||
|
||||
using namespace std::literals;
|
||||
|
@ -61,7 +62,7 @@ void logAddImpl(
|
|||
[[maybe_unused]] std::string_view file,
|
||||
[[maybe_unused]] long line,
|
||||
[[maybe_unused]] tr_log_level level,
|
||||
std::string_view msg,
|
||||
std::string&& msg,
|
||||
[[maybe_unused]] std::string_view name)
|
||||
{
|
||||
if (std::empty(msg))
|
||||
|
@ -110,7 +111,7 @@ void logAddImpl(
|
|||
auto* const newmsg = new tr_log_message{};
|
||||
newmsg->level = level;
|
||||
newmsg->when = tr_time();
|
||||
newmsg->message = msg;
|
||||
newmsg->message = std::move(msg);
|
||||
newmsg->file = file;
|
||||
newmsg->line = line;
|
||||
newmsg->name = name;
|
||||
|
@ -132,18 +133,24 @@ void logAddImpl(
|
|||
else
|
||||
{
|
||||
static auto const fp = tr_sys_file_get_std(TR_STD_SYS_FILE_ERR);
|
||||
|
||||
if (fp == TR_BAD_SYS_FILE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto timestr = std::array<char, 64>{};
|
||||
auto timestr = std::array<char, 64U>{};
|
||||
tr_logGetTimeStr(std::data(timestr), std::size(timestr));
|
||||
tr_sys_file_write_line(
|
||||
fp,
|
||||
!std::empty(name) ? fmt::format(FMT_STRING("[{:s}] {:s}: {:s}"), std::data(timestr), name, msg) :
|
||||
fmt::format(FMT_STRING("[{:s}] {:s}"), std::data(timestr), msg));
|
||||
|
||||
auto buf = tr_strbuf<char, 2048U>{};
|
||||
if (std::empty(name))
|
||||
{
|
||||
fmt::format_to(std::back_inserter(buf), "[{:s}] {:s}", std::data(timestr), msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::format_to(std::back_inserter(buf), "[{:s}] {:s}: {:s}", std::data(timestr), name, msg);
|
||||
}
|
||||
tr_sys_file_write_line(fp, buf);
|
||||
tr_sys_file_flush(fp);
|
||||
}
|
||||
#endif
|
||||
|
@ -208,7 +215,7 @@ char* tr_logGetTimeStr(char* buf, size_t buflen)
|
|||
return buf;
|
||||
}
|
||||
|
||||
void tr_logAddMessage(char const* file, long line, tr_log_level level, std::string_view msg, std::string_view name)
|
||||
void tr_logAddMessage(char const* file, long line, tr_log_level level, std::string&& msg, std::string_view name)
|
||||
{
|
||||
TR_ASSERT(!std::empty(msg));
|
||||
|
||||
|
@ -257,7 +264,7 @@ void tr_logAddMessage(char const* file, long line, tr_log_level level, std::stri
|
|||
}
|
||||
|
||||
// log the messages
|
||||
logAddImpl(filename, line, level, msg, name);
|
||||
logAddImpl(filename, line, level, std::move(msg), name);
|
||||
if (last_one)
|
||||
{
|
||||
logAddImpl(
|
||||
|
|
|
@ -89,7 +89,7 @@ void tr_logAddMessage(
|
|||
char const* source_file,
|
||||
long source_line,
|
||||
tr_log_level level,
|
||||
std::string_view msg,
|
||||
std::string&& msg,
|
||||
std::string_view module_name = {});
|
||||
|
||||
#define tr_logAddLevel(level, ...) \
|
||||
|
|
|
@ -2176,8 +2176,10 @@ void tr_torrent::on_tracker_response(tr_tracker_event const* event)
|
|||
case tr_tracker_event::Type::Warning:
|
||||
tr_logAddWarnTor(
|
||||
this,
|
||||
fmt::format(_("Tracker warning: '{warning}'"), fmt::arg("warning", event->text))
|
||||
.append(fmt::format(" ({})", tr_urlTrackerLogName(event->announce_url))));
|
||||
fmt::format(
|
||||
_("Tracker warning: '{warning}' ({url})"),
|
||||
fmt::arg("warning", event->text),
|
||||
fmt::arg("url", tr_urlTrackerLogName(event->announce_url))));
|
||||
error = TR_STAT_TRACKER_WARNING;
|
||||
error_announce_url = event->announce_url;
|
||||
error_string = event->text;
|
||||
|
|
Loading…
Reference in a new issue