Added small_map_threshold constexpr

This commit is contained in:
gabime 2024-03-17 00:36:52 +02:00
parent b95e493471
commit e1f5a45900

View File

@ -22,6 +22,8 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
static constexpr size_t small_map_threshold = 10;
namespace spdlog { namespace spdlog {
namespace details { namespace details {
@ -70,7 +72,7 @@ namespace spdlog {
// if the map is small do a sequential search, otherwise use the standard find() // if the map is small do a sequential search, otherwise use the standard find()
std::shared_ptr<logger> registry::get(const std::string &logger_name) { std::shared_ptr<logger> registry::get(const std::string &logger_name) {
if (loggers_.size() <= 10) { if (loggers_.size() <= small_map_threshold) {
for (const auto &[key, val]: loggers_) { for (const auto &[key, val]: loggers_) {
if (logger_name == key) { if (logger_name == key) {
return val; return val;
@ -89,7 +91,7 @@ namespace spdlog {
std::shared_ptr<logger> registry::get(std::string_view logger_name) { std::shared_ptr<logger> registry::get(std::string_view logger_name) {
std::lock_guard<std::mutex> lock(logger_map_mutex_); std::lock_guard<std::mutex> lock(logger_map_mutex_);
if (loggers_.size() <= 10) { if (loggers_.size() <= small_map_threshold) {
for (const auto &[key, val]: loggers_) { for (const auto &[key, val]: loggers_) {
if (logger_name == key) { if (logger_name == key) {
return val; return val;