Optimized nano seconds formatting

This commit is contained in:
gabime
2018-11-12 16:44:34 +02:00
parent 11d83515dd
commit 4a34cd0662
4 changed files with 40 additions and 4 deletions

View File

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

View File

@@ -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);
}
};