Skip to content

Commit

Permalink
Revert pr #3023 (std::string_view overloads for logger accessor for c…
Browse files Browse the repository at this point in the history
…++17)
  • Loading branch information
gabime committed Apr 30, 2024
1 parent fa6605d commit 37b8476
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 49 deletions.
24 changes: 0 additions & 24 deletions include/spdlog/details/registry-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,6 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::get(const std::string &logger_na
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() <= 10) {
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) {
return get(std::string_view(logger_name));
}
#endif

SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger() {
std::lock_guard<std::mutex> lock(logger_map_mutex_);
Expand Down
8 changes: 0 additions & 8 deletions include/spdlog/details/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include <string>
#include <unordered_map>

#if __cplusplus >= 201703L // C++17
#include <string_view>
#endif

namespace spdlog {
class logger;

Expand All @@ -37,10 +33,6 @@ class SPDLOG_API registry {
void register_logger(std::shared_ptr<logger> new_logger);
void initialize_logger(std::shared_ptr<logger> new_logger);
std::shared_ptr<logger> get(const std::string &logger_name);
#if __cplusplus >= 201703L // C++17
std::shared_ptr<logger> get(std::string_view logger_name);
std::shared_ptr<logger> get(const char *logger_name);
#endif
std::shared_ptr<logger> default_logger();

// Return raw ptr to the default logger.
Expand Down
9 changes: 0 additions & 9 deletions include/spdlog/spdlog-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ SPDLOG_INLINE std::shared_ptr<logger> get(const std::string &name) {
return details::registry::instance().get(name);
}

#if __cplusplus >= 201703L // C++17
SPDLOG_INLINE std::shared_ptr<logger> get(std::string_view name) {
return details::registry::instance().get(name);
}

SPDLOG_INLINE std::shared_ptr<logger> get(const char *name) {
return details::registry::instance().get(name);
}
#endif

SPDLOG_INLINE void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
details::registry::instance().set_formatter(std::move(formatter));
Expand Down
8 changes: 0 additions & 8 deletions include/spdlog/spdlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include <memory>
#include <string>

#if __cplusplus >= 201703L // C++17
#include <string_view>
#endif

namespace spdlog {

using default_factory = synchronous_factory;
Expand Down Expand Up @@ -54,10 +50,6 @@ SPDLOG_API void initialize_logger(std::shared_ptr<logger> logger);
// exist.
// example: spdlog::get("my_logger")->info("hello {}", "world");
SPDLOG_API std::shared_ptr<logger> get(const std::string &name);
#if __cplusplus >= 201703L // C++17
SPDLOG_API std::shared_ptr<logger> get(std::string_view name);
SPDLOG_API std::shared_ptr<logger> get(const char *name);
#endif

// Set global formatter. Each sink in each logger will get a clone of this object
SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
Expand Down

0 comments on commit 37b8476

Please sign in to comment.