Optimize ansicolor_sink to use array instead of map to find color codes

This commit is contained in:
gabime 2020-02-15 12:06:01 +02:00
parent 5c06306ccc
commit 695912c7cf
2 changed files with 3 additions and 2 deletions

View File

@ -147,6 +147,7 @@ enum level_enum
err = SPDLOG_LEVEL_ERROR, err = SPDLOG_LEVEL_ERROR,
critical = SPDLOG_LEVEL_CRITICAL, critical = SPDLOG_LEVEL_CRITICAL,
off = SPDLOG_LEVEL_OFF, off = SPDLOG_LEVEL_OFF,
n_levels
}; };
#if !defined(SPDLOG_LEVEL_NAMES) #if !defined(SPDLOG_LEVEL_NAMES)

View File

@ -9,7 +9,7 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <unordered_map> #include <array>
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
@ -80,7 +80,7 @@ private:
mutex_t &mutex_; mutex_t &mutex_;
bool should_do_colors_; bool should_do_colors_;
std::unique_ptr<spdlog::formatter> formatter_; std::unique_ptr<spdlog::formatter> formatter_;
std::unordered_map<level::level_enum, string_view_t, level::level_hasher> colors_; std::array<string_view_t , level::n_levels> colors_;
void print_ccode_(const string_view_t &color_code); void print_ccode_(const string_view_t &color_code);
void print_range_(const memory_buf_t &formatted, size_t start, size_t end); void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
}; };