clang-format
This commit is contained in:
parent
d99179f822
commit
d54e302a28
@ -12,8 +12,6 @@
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/details/pattern_formatter.h"
|
||||
|
||||
|
||||
|
||||
void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::details::padding_info padinfo)
|
||||
{
|
||||
fmt::memory_buffer dest;
|
||||
@ -23,50 +21,38 @@ void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::deta
|
||||
spdlog::details::scoped_pad p(wrapped_size, padinfo, dest);
|
||||
benchmark::DoNotOptimize(p);
|
||||
}
|
||||
// if(dest.size() != (padinfo.width_-wrapped_size))
|
||||
// {
|
||||
// printf("NOT GOOD wrapped_size=%zu\t padinfo.width= %zu\tdest = %zu\n", wrapped_size, padinfo.width_, dest.size());
|
||||
// }
|
||||
// if(dest.size() != (padinfo.width_-wrapped_size))
|
||||
// {
|
||||
// printf("NOT GOOD wrapped_size=%zu\t padinfo.width= %zu\tdest = %zu\n", wrapped_size, padinfo.width_, dest.size());
|
||||
// }
|
||||
dest.clear();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
using spdlog::details::padding_info;
|
||||
spdlog::set_pattern("[tid %t] %v");
|
||||
|
||||
|
||||
std::vector<size_t> sizes = {0, 2, 4, 8, 16, 32, 64, 128};
|
||||
|
||||
for (auto size:sizes)
|
||||
for (auto size : sizes)
|
||||
{
|
||||
size_t wrapped_size = 8;
|
||||
size_t padding_size = wrapped_size + size;
|
||||
|
||||
std::string title = "scoped_pad::left::" + std::to_string(size);
|
||||
|
||||
benchmark::RegisterBenchmark(title.c_str(),
|
||||
bench_scoped_pad,
|
||||
wrapped_size,
|
||||
padding_info(padding_size, padding_info::left));
|
||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::left));
|
||||
|
||||
title = "scoped_pad::right::" + std::to_string(size);
|
||||
benchmark::RegisterBenchmark(title.c_str(),
|
||||
bench_scoped_pad,
|
||||
wrapped_size,
|
||||
padding_info(padding_size, padding_info::right));
|
||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::right));
|
||||
|
||||
title = "scoped_pad::center::" + std::to_string(size);
|
||||
benchmark::RegisterBenchmark(title.c_str(),
|
||||
bench_scoped_pad,
|
||||
wrapped_size,
|
||||
padding_info(padding_size, padding_info::center));
|
||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::center));
|
||||
}
|
||||
|
||||
|
||||
|
||||
benchmark::Initialize(&argc, argv);
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
|
@ -48,29 +48,29 @@ struct padding_info
|
||||
class scoped_pad
|
||||
{
|
||||
public:
|
||||
scoped_pad(size_t wrapped_size, padding_info &padinfo, fmt::memory_buffer &dest):
|
||||
padinfo_(padinfo)
|
||||
scoped_pad(size_t wrapped_size, padding_info &padinfo, fmt::memory_buffer &dest)
|
||||
: padinfo_(padinfo)
|
||||
, dest_(dest)
|
||||
{
|
||||
|
||||
if(padinfo_.width_ <= wrapped_size)
|
||||
if (padinfo_.width_ <= wrapped_size)
|
||||
{
|
||||
total_pad_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
total_pad_= padinfo.width_ - wrapped_size;
|
||||
total_pad_ = padinfo.width_ - wrapped_size;
|
||||
if (padinfo_.side_ == padding_info::left)
|
||||
{
|
||||
pad_it(total_pad_);
|
||||
total_pad_ = 0;
|
||||
}
|
||||
else if(padinfo_.side_ == padding_info::center)
|
||||
else if (padinfo_.side_ == padding_info::center)
|
||||
{
|
||||
auto half_pad = total_pad_/ 2;
|
||||
auto half_pad = total_pad_ / 2;
|
||||
auto reminder = total_pad_ & 1;
|
||||
pad_it(half_pad);
|
||||
total_pad_= half_pad + reminder; // for the right side
|
||||
total_pad_ = half_pad + reminder; // for the right side
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public:
|
||||
|
||||
~scoped_pad()
|
||||
{
|
||||
if(total_pad_)
|
||||
if (total_pad_)
|
||||
{
|
||||
pad_it(total_pad_);
|
||||
}
|
||||
@ -90,12 +90,11 @@ public:
|
||||
private:
|
||||
void pad_it(size_t count)
|
||||
{
|
||||
//count = std::min(count, spaces_.size());
|
||||
// count = std::min(count, spaces_.size());
|
||||
assert(count <= spaces_.size());
|
||||
fmt_helper::append_string_view(string_view_t(spaces_.data(), count), dest_);
|
||||
}
|
||||
|
||||
|
||||
const padding_info &padinfo_;
|
||||
fmt::memory_buffer &dest_;
|
||||
size_t total_pad_;
|
||||
@ -870,12 +869,11 @@ public:
|
||||
}
|
||||
|
||||
// use by default full formatter for if pattern is not given
|
||||
explicit pattern_formatter(
|
||||
pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
|
||||
: pattern_()
|
||||
, eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
, last_log_secs_(0)
|
||||
explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
|
||||
: pattern_()
|
||||
, eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info()));
|
||||
|
Loading…
Reference in New Issue
Block a user