diff options
| author | 2018-07-20 15:27:17 -0400 | |
|---|---|---|
| committer | 2018-07-20 15:27:20 -0400 | |
| commit | 457d1b4490dbc293246f372532a81a9e90d366c4 (patch) | |
| tree | 93eb2026cadad03ab9d52be843a9446ff180ecf0 /src | |
| parent | Merge pull request #740 from Subv/acc_crash (diff) | |
| download | yuzu-457d1b4490dbc293246f372532a81a9e90d366c4.tar.gz yuzu-457d1b4490dbc293246f372532a81a9e90d366c4.tar.xz yuzu-457d1b4490dbc293246f372532a81a9e90d366c4.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/logging/backend.cpp | 20 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 5 |
2 files changed, 13 insertions, 12 deletions
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: | |||
| 48 | backends.push_back(std::move(backend)); | 48 | backends.push_back(std::move(backend)); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void RemoveBackend(const std::string& backend_name) { | 51 | void RemoveBackend(std::string_view backend_name) { |
| 52 | std::lock_guard<std::mutex> lock(writing_mutex); | 52 | std::lock_guard<std::mutex> lock(writing_mutex); |
| 53 | auto it = std::remove_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { | 53 | const auto it = |
| 54 | return !strcmp(i->GetName(), backend_name.c_str()); | 54 | std::remove_if(backends.begin(), backends.end(), |
| 55 | }); | 55 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); |
| 56 | backends.erase(it, backends.end()); | 56 | backends.erase(it, backends.end()); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| @@ -64,10 +64,10 @@ public: | |||
| 64 | filter = f; | 64 | filter = f; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | Backend* GetBackend(const std::string& backend_name) { | 67 | Backend* GetBackend(std::string_view backend_name) { |
| 68 | auto it = std::find_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { | 68 | const auto it = |
| 69 | return !strcmp(i->GetName(), backend_name.c_str()); | 69 | std::find_if(backends.begin(), backends.end(), |
| 70 | }); | 70 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); |
| 71 | if (it == backends.end()) | 71 | if (it == backends.end()) |
| 72 | return nullptr; | 72 | return nullptr; |
| 73 | return it->get(); | 73 | return it->get(); |
| @@ -265,11 +265,11 @@ void AddBackend(std::unique_ptr<Backend> backend) { | |||
| 265 | Impl::Instance().AddBackend(std::move(backend)); | 265 | Impl::Instance().AddBackend(std::move(backend)); |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | void RemoveBackend(const std::string& backend_name) { | 268 | void RemoveBackend(std::string_view backend_name) { |
| 269 | Impl::Instance().RemoveBackend(backend_name); | 269 | Impl::Instance().RemoveBackend(backend_name); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | Backend* GetBackend(const std::string& backend_name) { | 272 | Backend* GetBackend(std::string_view backend_name) { |
| 273 | return Impl::Instance().GetBackend(backend_name); | 273 | return Impl::Instance().GetBackend(backend_name); |
| 274 | } | 274 | } |
| 275 | 275 | ||
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 57cdf6b2d..45609a535 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <cstdarg> | 7 | #include <cstdarg> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include <string_view> | ||
| 10 | #include <utility> | 11 | #include <utility> |
| 11 | #include "common/file_util.h" | 12 | #include "common/file_util.h" |
| 12 | #include "common/logging/filter.h" | 13 | #include "common/logging/filter.h" |
| @@ -106,9 +107,9 @@ private: | |||
| 106 | 107 | ||
| 107 | void AddBackend(std::unique_ptr<Backend> backend); | 108 | void AddBackend(std::unique_ptr<Backend> backend); |
| 108 | 109 | ||
| 109 | void RemoveBackend(const std::string& backend_name); | 110 | void RemoveBackend(std::string_view backend_name); |
| 110 | 111 | ||
| 111 | Backend* GetBackend(const std::string& backend_name); | 112 | Backend* GetBackend(std::string_view backend_name); |
| 112 | 113 | ||
| 113 | /** | 114 | /** |
| 114 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods | 115 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods |