Skip to content

Commit

Permalink
Added small_map_threshold constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Mar 16, 2024
1 parent b95e493 commit e1f5a45
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/details/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <string>
#include <unordered_map>

static constexpr size_t small_map_threshold = 10;

namespace spdlog {
namespace details {

Expand Down Expand Up @@ -70,7 +72,7 @@ namespace spdlog {

// 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) {
if (loggers_.size() <= 10) {
if (loggers_.size() <= small_map_threshold) {
for (const auto &[key, val]: loggers_) {
if (logger_name == key) {
return val;
Expand All @@ -89,7 +91,7 @@ namespace spdlog {
std::shared_ptr<logger> registry::get(std::string_view logger_name) {
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_) {
if (logger_name == key) {
return val;
Expand Down

0 comments on commit e1f5a45

Please sign in to comment.