From 23587b0d9aebad231d7ba4f16873d70edd2b9dee Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 17 Mar 2024 01:20:26 +0200 Subject: [PATCH] Fixed regisry-inl.h --- include/spdlog/details/registry-inl.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index 695f2974..c55b0931 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -78,20 +78,10 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr new_logge } } -// if the map is small do a sequential search, otherwise use the standard find() -std::shared_ptr registry::get(const std::string &logger_name) { - 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; - } +SPDLOG_INLINE 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 __cplusplus >= 201703L // C++17