diff --git a/src/details/registry.cpp b/src/details/registry.cpp index d96a9247..efb555c3 100644 --- a/src/details/registry.cpp +++ b/src/details/registry.cpp @@ -68,15 +68,27 @@ namespace spdlog { } } + // if the map is small do a sequential search, otherwise use the standard find() std::shared_ptr registry::get(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - auto found = loggers_.find(logger_name); - return found == loggers_.end() ? nullptr : found->second; + if (loggers_.size() <= 20) { + for (const auto &[key, val]: loggers_) { + if (logger_name == key) { + return val; + } + } + return nullptr; + } + else { + auto found = loggers_.find(logger_name); + return found == loggers_.end() ? nullptr : found->second; + } } + // if the map is small do a sequential search and avoid creating string for find(logger_name) + // otherwise use the standard find() std::shared_ptr registry::get(std::string_view logger_name) { std::lock_guard lock(logger_map_mutex_); - // 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) {