From 0071739201c8cf56bcf4203eb5e9de38eb679aad Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 21 Nov 2020 22:28:35 +0800 Subject: [PATCH] compressor: pass string_view instead of string this allows us to find by string without creating a std::string instance, even if this string is not nul terminated. Signed-off-by: Kefu Chai --- src/compressor/Compressor.cc | 6 ++++-- src/compressor/Compressor.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compressor/Compressor.cc b/src/compressor/Compressor.cc index 4cd3406d7a9..fa0f052f69b 100644 --- a/src/compressor/Compressor.cc +++ b/src/compressor/Compressor.cc @@ -37,7 +37,8 @@ const char* Compressor::get_comp_alg_name(int a) { return p->first; } -boost::optional Compressor::get_comp_alg_type(const std::string &s) { +boost::optional +Compressor::get_comp_alg_type(std::string_view s) { auto p = std::find_if(std::cbegin(compression_algorithms), std::cend(compression_algorithms), [&s](const auto& kv) { return kv.first == s; }); @@ -56,7 +57,8 @@ const char *Compressor::get_comp_mode_name(int m) { default: return "???"; } } -boost::optional Compressor::get_comp_mode_type(const std::string &s) { +boost::optional +Compressor::get_comp_mode_type(std::string_view s) { if (s == "force") return COMP_FORCE; if (s == "aggressive") diff --git a/src/compressor/Compressor.h b/src/compressor/Compressor.h index d615e866b55..0a45a990a87 100644 --- a/src/compressor/Compressor.h +++ b/src/compressor/Compressor.h @@ -76,10 +76,10 @@ public: #endif static const char* get_comp_alg_name(int a); - static boost::optional get_comp_alg_type(const std::string &s); + static boost::optional get_comp_alg_type(std::string_view s); static const char *get_comp_mode_name(int m); - static boost::optional get_comp_mode_type(const std::string &s); + static boost::optional get_comp_mode_type(std::string_view s); Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) { } -- 2.39.5