From: Kefu Chai Date: Fri, 22 Mar 2019 03:57:02 +0000 (+0800) Subject: common/config_values: use string_view for keys X-Git-Tag: v15.0.0~115^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8e4686226c5207d5b2d612d95925a51cb08acd1e;p=ceph-ci.git common/config_values: use string_view for keys the contained char sequences are either static char strings or strings in `Option` instances. so no need to keep another copy of string around. Signed-off-by: Kefu Chai --- diff --git a/src/common/config_values.cc b/src/common/config_values.cc index 24f556e35a2..bc7fc8028a9 100644 --- a/src/common/config_values.cc +++ b/src/common/config_values.cc @@ -4,7 +4,7 @@ #include "config.h" ConfigValues::set_value_result_t -ConfigValues::set_value(const std::string& key, +ConfigValues::set_value(const std::string_view key, Option::value_t&& new_value, int level) { @@ -30,7 +30,7 @@ ConfigValues::set_value(const std::string& key, } } -int ConfigValues::rm_val(const std::string& key, int level) +int ConfigValues::rm_val(const std::string_view key, int level) { auto i = values.find(key); if (i == values.end()) { @@ -50,7 +50,7 @@ int ConfigValues::rm_val(const std::string& key, int level) } std::pair -ConfigValues::get_value(const std::string& name, int level) const +ConfigValues::get_value(const std::string_view name, int level) const { auto p = values.find(name); if (p != values.end() && !p->second.empty()) { @@ -78,7 +78,7 @@ void ConfigValues::set_logging(int which, const char* val) } } -bool ConfigValues::contains(const std::string& key) const +bool ConfigValues::contains(const std::string_view key) const { return values.count(key); } diff --git a/src/common/config_values.h b/src/common/config_values.h index fdfff2b16f3..fe7b36a40a7 100644 --- a/src/common/config_values.h +++ b/src/common/config_values.h @@ -17,7 +17,7 @@ // debug logging settings, and some other "unnamed" settings, like entity name of // the daemon. class ConfigValues { - using values_t = std::map>; + using values_t = std::map>; values_t values; // for populating md_config_impl::legacy_values in ctor friend struct md_config_t; @@ -80,21 +80,21 @@ public: /** * @return true if changed, false otherwise */ - set_value_result_t set_value(const std::string& key, + set_value_result_t set_value(std::string_view key, Option::value_t&& value, int level); - int rm_val(const std::string& key, int level); + int rm_val(const std::string_view key, int level); void set_logging(int which, const char* val); /** * @param level the level of the setting, -1 for the one with the * highest-priority */ - std::pair get_value(const std::string& name, + std::pair get_value(const std::string_view name, int level) const; template void for_each(Func&& func) const { for (const auto& [name,configs] : values) { func(name, configs); } } - bool contains(const std::string& key) const; + bool contains(const std::string_view key) const; };