mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 18:41:35 +08:00
if the map is small do a sequential search, otherwise use the standard find()
This commit is contained in:
parent
06e4631dde
commit
4a31ed38d3
@ -68,15 +68,27 @@ 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) {
|
||||
std::lock_guard<std::mutex> 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<logger> registry::get(std::string_view logger_name) {
|
||||
std::lock_guard<std::mutex> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user