mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 10:29:02 +08:00
Use fmt::string_view when logging a C string to avoid unnecessary copy
This commit is contained in:
@@ -47,7 +47,7 @@ protected:
|
||||
fmt::memory_buffer formatted;
|
||||
if (use_raw_msg_)
|
||||
{
|
||||
details::fmt_helper::append_buf(msg.raw, formatted);
|
||||
details::fmt_helper::append_msg(msg, formatted);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -53,7 +53,12 @@ public:
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
::syslog(syslog_prio_from_level(msg), "%s", fmt::to_string(msg.raw).c_str());
|
||||
if (msg.c_string.data() != nullptr)
|
||||
{
|
||||
::syslog(syslog_prio_from_level(msg), "%.*s", static_cast<int>(msg.c_string.size()), msg.c_string.data());
|
||||
} else {
|
||||
::syslog(syslog_prio_from_level(msg), "%s", fmt::to_string(msg.raw).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
Reference in New Issue
Block a user