diff --git a/src/details/registry.cpp b/src/details/registry.cpp index 9944f54c..d96a9247 100644 --- a/src/details/registry.cpp +++ b/src/details/registry.cpp @@ -12,7 +12,9 @@ #ifdef _WIN32 #include "spdlog/sinks/wincolor_sink.h" #else + #include "spdlog/sinks/ansicolor_sink.h" + #endif #endif // SPDLOG_DISABLE_DEFAULT_LOGGER @@ -74,12 +76,20 @@ namespace spdlog { std::shared_ptr registry::get(std::string_view logger_name) { std::lock_guard lock(logger_map_mutex_); - for (const auto &[key, val]: loggers_) { - if (logger_name == key) { - return val; + // if the map is small do a sequential search to avoid creating string for find(logger_name) + if (loggers_.size() <= 20) { + for (const auto &[key, val]: loggers_) { + if (logger_name == key) { + return val; + } } + return nullptr; + } + // otherwise use the normal map lookup + else { + auto found = loggers_.find(std::string(logger_name)); + return found == loggers_.end() ? nullptr : found->second; } - return nullptr; } std::shared_ptr registry::get(const char *logger_name) {