mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Use find if registry is bigger than 20 in registry::get(std::string_view logger_name)
This commit is contained in:
parent
8cfd4a7e7b
commit
4052bc0621
@ -78,21 +78,40 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE std::shared_ptr<logger> registry::get(const std::string &logger_name) {
|
// if the map is small do a sequential search, otherwise use the standard find()
|
||||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
std::shared_ptr<logger> registry::get(const std::string &logger_name) {
|
||||||
auto found = loggers_.find(logger_name);
|
if (loggers_.size() <= 20) {
|
||||||
return found == loggers_.end() ? nullptr : found->second;
|
for (const auto &[key, val]: loggers_) {
|
||||||
}
|
if (logger_name == key) {
|
||||||
|
|
||||||
#if __cplusplus >= 201703L // C++17
|
|
||||||
SPDLOG_INLINE std::shared_ptr<logger> registry::get(std::string_view logger_name) {
|
|
||||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
||||||
for (const auto &[key, val] : loggers_) {
|
|
||||||
if (key == logger_name) {
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto found = loggers_.find(logger_name);
|
||||||
|
return found == loggers_.end() ? nullptr : found->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L // C++17
|
||||||
|
// if the map is small do a sequential search and avoid creating string for find(logger_name)
|
||||||
|
// otherwise use the standard find()
|
||||||
|
SPDLOG_INLINE std::shared_ptr<logger> registry::get(std::string_view logger_name) {
|
||||||
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||||
|
if (loggers_.size() <= 20) {
|
||||||
|
for (const auto &[key, val]: loggers_) {
|
||||||
|
if (logger_name == key) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
// otherwise use the normal map lookup
|
||||||
|
else {
|
||||||
|
auto found = loggers_.find(std::string(logger_name));
|
||||||
|
return found == loggers_.end() ? nullptr : found->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE std::shared_ptr<logger> registry::get(const char *logger_name) {
|
SPDLOG_INLINE std::shared_ptr<logger> registry::get(const char *logger_name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user