Skip to content

Commit

Permalink
Optimize ansicolor_sink to use array instead of map to find color codes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Feb 15, 2020
1 parent 5c06306 commit 695912c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/spdlog/common.h
Expand Up @@ -147,6 +147,7 @@ enum level_enum
err = SPDLOG_LEVEL_ERROR,
critical = SPDLOG_LEVEL_CRITICAL,
off = SPDLOG_LEVEL_OFF,
n_levels
};

#if !defined(SPDLOG_LEVEL_NAMES)
Expand Down
4 changes: 2 additions & 2 deletions include/spdlog/sinks/ansicolor_sink.h
Expand Up @@ -9,7 +9,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <array>

namespace spdlog {
namespace sinks {
Expand Down Expand Up @@ -80,7 +80,7 @@ class ansicolor_sink : public sink
mutex_t &mutex_;
bool should_do_colors_;
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_range_(const memory_buf_t &formatted, size_t start, size_t end);
};
Expand Down

0 comments on commit 695912c

Please sign in to comment.