Use fmt::string_view when logging a C string to avoid unnecessary copy

This commit is contained in:
Jerome Meyer
2018-10-17 10:40:41 -04:00
parent 4b66e94ecf
commit cb71fea0f6
10 changed files with 93 additions and 9 deletions

View File

@@ -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)
{