mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 02:19:35 +08:00
Use fmt::string_view when logging a C string to avoid unnecessary copy
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "chrono"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
|
||||
// Some fmt helpers to efficiently format and pad ints and strings
|
||||
@@ -40,6 +41,17 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
dest.append(i.data(), i.data() + i.size());
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void append_msg(const details::log_msg &msg, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
auto *c_buf = msg.c_string.data();
|
||||
if (c_buf != nullptr) {
|
||||
dest.append(c_buf, c_buf + msg.c_string.size());
|
||||
} else {
|
||||
append_buf(msg.raw, dest);
|
||||
}
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
|
Reference in New Issue
Block a user