From 457d1b4490dbc293246f372532a81a9e90d366c4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 15:27:17 -0400 Subject: logging/backend: Use std::string_view in RemoveBackend() and GetBackend() These can just use a view to a string since its only comparing against two names in both cases for matches. This avoids constructing std::string instances where they aren't necessary. --- src/common/logging/backend.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/common/logging/backend.cpp') diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ed1e93cc2..3745af9df 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -48,11 +48,11 @@ public: backends.push_back(std::move(backend)); } - void RemoveBackend(const std::string& backend_name) { + void RemoveBackend(std::string_view backend_name) { std::lock_guard lock(writing_mutex); - auto it = std::remove_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { - return !strcmp(i->GetName(), backend_name.c_str()); - }); + const auto it = + std::remove_if(backends.begin(), backends.end(), + [&backend_name](const auto& i) { return backend_name == i->GetName(); }); backends.erase(it, backends.end()); } @@ -64,10 +64,10 @@ public: filter = f; } - Backend* GetBackend(const std::string& backend_name) { - auto it = std::find_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { - return !strcmp(i->GetName(), backend_name.c_str()); - }); + Backend* GetBackend(std::string_view backend_name) { + const auto it = + std::find_if(backends.begin(), backends.end(), + [&backend_name](const auto& i) { return backend_name == i->GetName(); }); if (it == backends.end()) return nullptr; return it->get(); @@ -265,11 +265,11 @@ void AddBackend(std::unique_ptr backend) { Impl::Instance().AddBackend(std::move(backend)); } -void RemoveBackend(const std::string& backend_name) { +void RemoveBackend(std::string_view backend_name) { Impl::Instance().RemoveBackend(backend_name); } -Backend* GetBackend(const std::string& backend_name) { +Backend* GetBackend(std::string_view backend_name) { return Impl::Instance().GetBackend(backend_name); } -- cgit v1.2.3 From 7a1a860abe6a6032353209a3df3841ee574877a8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 15:31:25 -0400 Subject: logging/backend: Add missing standard includes A few inclusions were being satisfied indirectly. To prevent breakages in the future, include these directly. --- src/common/logging/backend.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/common/logging/backend.cpp') diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 3745af9df..59b999935 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -3,19 +3,20 @@ // Refer to the license.txt file included. #include -#include +#include #include #include #include #include +#include #include +#include #ifdef _WIN32 #include // For _SH_DENYWR #else #define _SH_DENYWR 0 #endif #include "common/assert.h" -#include "common/common_funcs.h" // snprintf compatibility define #include "common/logging/backend.h" #include "common/logging/log.h" #include "common/logging/text_formatter.h" -- cgit v1.2.3