mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 02:19:35 +08:00
Optimized nano seconds formatting
This commit is contained in:
@@ -110,6 +110,19 @@ inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
pad3(static_cast<int>(n % 1000), dest);
|
||||
}
|
||||
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad9(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
if (n > 99999999)
|
||||
{
|
||||
append_int(n, dest);
|
||||
return;
|
||||
}
|
||||
pad6(static_cast<int>(n / 1000), dest);
|
||||
pad3(static_cast<int>(n % 1000), dest);
|
||||
}
|
||||
|
||||
// return fraction of a second of the given time_point.
|
||||
// e.g.
|
||||
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
|
||||
|
@@ -486,7 +486,8 @@ public:
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
|
||||
auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
|
||||
fmt::format_to(dest, "{:09}", ns.count());
|
||||
fmt_helper::pad9(static_cast<size_t>(ns.count()), dest);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user