mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-24 06:32:06 +08:00
Micro optimized some formatter flags
This commit is contained in:
parent
52e2722412
commit
fb1a3a3a12
@ -447,13 +447,19 @@ public:
|
||||
: flag_formatter(padinfo){};
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
|
||||
if (padinfo_.width_)
|
||||
{
|
||||
const size_t field_size = 3;
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
|
||||
auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
|
||||
fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_helper::pad3(static_cast<uint32_t>(millis.count()), dest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// microseconds
|
||||
@ -464,13 +470,19 @@ public:
|
||||
: flag_formatter(padinfo){};
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time);
|
||||
if (padinfo_.width_)
|
||||
{
|
||||
const size_t field_size = 6;
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
|
||||
auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time);
|
||||
fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// nanoseconds
|
||||
@ -481,13 +493,19 @@ public:
|
||||
: flag_formatter(padinfo){};
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
|
||||
if (padinfo_.width_)
|
||||
{
|
||||
const size_t field_size = 9;
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
|
||||
auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
|
||||
fmt_helper::pad9(static_cast<size_t>(ns.count()), dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_helper::pad9(static_cast<size_t>(ns.count()), dest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// seconds since epoch
|
||||
@ -651,11 +669,18 @@ public:
|
||||
: flag_formatter(padinfo){};
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
if (padinfo_.width_)
|
||||
{
|
||||
const auto field_size = fmt_helper::count_digits(msg.thread_id);
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
fmt_helper::append_int(msg.thread_id, dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_helper::append_int(msg.thread_id, dest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Current pid
|
||||
@ -668,10 +693,17 @@ public:
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
const auto pid = static_cast<uint32_t>(details::os::pid());
|
||||
if (padinfo_.width_)
|
||||
{
|
||||
const size_t field_size = fmt::internal::count_digits(pid);
|
||||
scoped_pad p(field_size, padinfo_, dest);
|
||||
fmt_helper::append_int(pid, dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt_helper::append_int(pid, dest);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// message counter formatter
|
||||
|
Loading…
Reference in New Issue
Block a user