mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-14 17:52:05 +08:00
Use find if registry is bigger than 20
This commit is contained in:
parent
e750d2219e
commit
06e4631dde
@ -12,7 +12,9 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "spdlog/sinks/wincolor_sink.h"
|
#include "spdlog/sinks/wincolor_sink.h"
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include "spdlog/sinks/ansicolor_sink.h"
|
#include "spdlog/sinks/ansicolor_sink.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||||
|
|
||||||
@ -74,12 +76,20 @@ 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_);
|
||||||
for (const auto &[key, val]: loggers_) {
|
// if the map is small do a sequential search to avoid creating string for find(logger_name)
|
||||||
if (logger_name == key) {
|
if (loggers_.size() <= 20) {
|
||||||
return val;
|
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;
|
||||||
}
|
}
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<logger> registry::get(const char *logger_name) {
|
std::shared_ptr<logger> registry::get(const char *logger_name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user