Commit d54e302a authored by gabime's avatar gabime

clang-format

parent d99179f8
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/details/pattern_formatter.h" #include "spdlog/details/pattern_formatter.h"
void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::details::padding_info padinfo) void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::details::padding_info padinfo)
{ {
fmt::memory_buffer dest; fmt::memory_buffer dest;
...@@ -23,50 +21,38 @@ void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::deta ...@@ -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); spdlog::details::scoped_pad p(wrapped_size, padinfo, dest);
benchmark::DoNotOptimize(p); benchmark::DoNotOptimize(p);
} }
// if(dest.size() != (padinfo.width_-wrapped_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()); // printf("NOT GOOD wrapped_size=%zu\t padinfo.width= %zu\tdest = %zu\n", wrapped_size, padinfo.width_, dest.size());
// } // }
dest.clear(); dest.clear();
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
using spdlog::details::padding_info; using spdlog::details::padding_info;
spdlog::set_pattern("[tid %t] %v"); spdlog::set_pattern("[tid %t] %v");
std::vector<size_t> sizes = {0, 2, 4, 8, 16, 32, 64, 128}; 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 wrapped_size = 8;
size_t padding_size = wrapped_size + size; size_t padding_size = wrapped_size + size;
std::string title = "scoped_pad::left::" + std::to_string(size); std::string title = "scoped_pad::left::" + std::to_string(size);
benchmark::RegisterBenchmark(title.c_str(), benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::left));
bench_scoped_pad,
wrapped_size,
padding_info(padding_size, padding_info::left));
title = "scoped_pad::right::" + std::to_string(size); title = "scoped_pad::right::" + std::to_string(size);
benchmark::RegisterBenchmark(title.c_str(), benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::right));
bench_scoped_pad,
wrapped_size,
padding_info(padding_size, padding_info::right));
title = "scoped_pad::center::" + std::to_string(size); title = "scoped_pad::center::" + std::to_string(size);
benchmark::RegisterBenchmark(title.c_str(), benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::center));
bench_scoped_pad,
wrapped_size,
padding_info(padding_size, padding_info::center));
} }
benchmark::Initialize(&argc, argv); benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks(); benchmark::RunSpecifiedBenchmarks();
} }
...@@ -48,29 +48,29 @@ struct padding_info ...@@ -48,29 +48,29 @@ struct padding_info
class scoped_pad class scoped_pad
{ {
public: public:
scoped_pad(size_t wrapped_size, padding_info &padinfo, fmt::memory_buffer &dest): scoped_pad(size_t wrapped_size, padding_info &padinfo, fmt::memory_buffer &dest)
padinfo_(padinfo) : padinfo_(padinfo)
, dest_(dest) , dest_(dest)
{ {
if(padinfo_.width_ <= wrapped_size) if (padinfo_.width_ <= wrapped_size)
{ {
total_pad_ = 0; total_pad_ = 0;
return; return;
} }
total_pad_= padinfo.width_ - wrapped_size; total_pad_ = padinfo.width_ - wrapped_size;
if (padinfo_.side_ == padding_info::left) if (padinfo_.side_ == padding_info::left)
{ {
pad_it(total_pad_); pad_it(total_pad_);
total_pad_ = 0; 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; auto reminder = total_pad_ & 1;
pad_it(half_pad); 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: ...@@ -81,7 +81,7 @@ public:
~scoped_pad() ~scoped_pad()
{ {
if(total_pad_) if (total_pad_)
{ {
pad_it(total_pad_); pad_it(total_pad_);
} }
...@@ -90,12 +90,11 @@ public: ...@@ -90,12 +90,11 @@ public:
private: private:
void pad_it(size_t count) void pad_it(size_t count)
{ {
//count = std::min(count, spaces_.size()); // count = std::min(count, spaces_.size());
assert(count <= spaces_.size()); assert(count <= spaces_.size());
fmt_helper::append_string_view(string_view_t(spaces_.data(), count), dest_); fmt_helper::append_string_view(string_view_t(spaces_.data(), count), dest_);
} }
const padding_info &padinfo_; const padding_info &padinfo_;
fmt::memory_buffer &dest_; fmt::memory_buffer &dest_;
size_t total_pad_; size_t total_pad_;
...@@ -870,8 +869,7 @@ public: ...@@ -870,8 +869,7 @@ public:
} }
// use by default full formatter for if pattern is not given // use by default full formatter for if pattern is not given
explicit pattern_formatter( explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
: pattern_() : pattern_()
, eol_(std::move(eol)) , eol_(std::move(eol))
, pattern_time_type_(time_type) , pattern_time_type_(time_type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment