Commit 4a31ed3 1 parent 06e4631 commit 4a31ed3 Copy full SHA for 4a31ed3
File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -68,15 +68,27 @@ namespace spdlog {
68
68
}
69
69
}
70
70
71
+ // if the map is small do a sequential search, otherwise use the standard find()
71
72
std::shared_ptr<logger> registry::get (const std::string &logger_name) {
72
- std::lock_guard<std::mutex> lock (logger_map_mutex_);
73
- auto found = loggers_.find (logger_name);
74
- return found == loggers_.end () ? nullptr : found->second ;
73
+ if (loggers_.size () <= 20 ) {
74
+ for (const auto &[key, val]: loggers_) {
75
+ if (logger_name == key) {
76
+ return val;
77
+ }
78
+ }
79
+ return nullptr ;
80
+ }
81
+ else {
82
+ auto found = loggers_.find (logger_name);
83
+ return found == loggers_.end () ? nullptr : found->second ;
84
+ }
75
85
}
76
86
87
+ // if the map is small do a sequential search and avoid creating string for find(logger_name)
88
+ // otherwise use the standard find()
77
89
std::shared_ptr<logger> registry::get (std::string_view logger_name) {
78
90
std::lock_guard<std::mutex> lock (logger_map_mutex_);
79
- // if the map is small do a sequential search to avoid creating string for find(logger_name)
91
+
80
92
if (loggers_.size () <= 20 ) {
81
93
for (const auto &[key, val]: loggers_) {
82
94
if (logger_name == key) {
You can’t perform that action at this time.
0 commit comments