Optimize ansicolor_sink to use array instead of map to find color codes
This commit is contained in:
		@@ -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)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user