From: Kefu Chai Date: Sat, 21 Nov 2020 14:28:35 +0000 (+0800) Subject: compressor: pass string_view instead of string X-Git-Tag: v16.1.0~341^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0071739201c8cf56bcf4203eb5e9de38eb679aad;p=ceph.git 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 --- diff --git a/src/compressor/Compressor.cc b/src/compressor/Compressor.cc index 4cd3406d7a9f..fa0f052f69b1 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 d615e866b55a..0a45a990a87f 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) { }