From: Kefu Chai Date: Wed, 29 Jul 2020 10:17:23 +0000 (+0800) Subject: common: let get_my_sections() return the section names X-Git-Tag: v16.1.0~1497^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=502013affbec9ccfc011a45c4b2bef821a19a302;p=ceph.git common: let get_my_sections() return the section names instead of passing the output parameter just let it return the section names. C++17 enfoces the copy elision in this case, so no need to pass the output parameter for saving the overhead of creating an temporary object and copying it. Signed-off-by: Kefu Chai --- diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 3bd219f11074..25c641e9ad3b 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -738,8 +738,7 @@ int main(int argc, const char **argv) ipaddrs = monmap.get_addrs(g_conf()->name.get_id()); // print helpful warning if the conf file doesn't match - std::vector my_sections; - g_conf().get_my_sections(my_sections); + std::vector my_sections = g_conf().get_my_sections(); std::string mon_addr_str; if (g_conf().get_val_from_conf_file(my_sections, "mon addr", mon_addr_str, true) == 0) { diff --git a/src/common/config.cc b/src/common/config.cc index 3f7fe25181e1..f53d453825f7 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -396,8 +396,7 @@ int md_config_t::parse_config_files(ConfigValues& values, } } - std::vector my_sections; - _get_my_sections(values, my_sections); + std::vector my_sections = get_my_sections(values); for (const auto &i : schema) { const auto &opt = i.second; std::string val; @@ -1316,20 +1315,12 @@ void md_config_t::get_all_keys(std::vector *keys) const { * looking. The lowest priority section is the one we look in only if all * others had nothing. This should always be the global section. */ -void md_config_t::get_my_sections(const ConfigValues& values, - std::vector §ions) const +std::vector +md_config_t::get_my_sections(const ConfigValues& values) const { - _get_my_sections(values, sections); -} - -void md_config_t::_get_my_sections(const ConfigValues& values, - std::vector §ions) const -{ - sections.push_back(values.name.to_str()); - - sections.push_back(values.name.get_type_name().data()); - - sections.push_back("global"); + return {values.name.to_str(), + values.name.get_type_name().data(), + "global"}; } // Return a list of all sections diff --git a/src/common/config.h b/src/common/config.h index d1f3dac2d42f..0fa89382b8a2 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -205,8 +205,7 @@ public: void get_all_keys(std::vector *keys) const; // Return a list of all the sections that the current entity is a member of. - void get_my_sections(const ConfigValues& values, - std::vector §ions) const; + std::vector get_my_sections(const ConfigValues& values) const; // Return a list of all sections int get_all_sections(std::vector §ions) const; @@ -265,9 +264,6 @@ private: void _show_config(const ConfigValues& values, std::ostream *out, ceph::Formatter *f) const; - void _get_my_sections(const ConfigValues& values, - std::vector §ions) const; - int _get_val_from_conf_file(const std::vector §ions, const std::string_view key, std::string &out) const; diff --git a/src/common/config_proxy.h b/src/common/config_proxy.h index 9c0850fd08e1..f66e7c410e6a 100644 --- a/src/common/config_proxy.h +++ b/src/common/config_proxy.h @@ -170,9 +170,9 @@ public: std::lock_guard l{lock}; return config.diff(values, f, name); } - void get_my_sections(std::vector §ions) const { + std::vector get_my_sections() const { std::lock_guard l{lock}; - config.get_my_sections(values, sections); + return config.get_my_sections(values); } int get_all_sections(std::vector& sections) const { std::lock_guard l{lock}; diff --git a/src/tools/ceph_conf.cc b/src/tools/ceph_conf.cc index a86d436ae9ae..df5384a9e91d 100644 --- a/src/tools/ceph_conf.cc +++ b/src/tools/ceph_conf.cc @@ -117,11 +117,10 @@ static int list_sections(const std::string &prefix, static int lookup(const std::deque §ions, const std::string &key, bool resolve_search) { - std::vector my_sections; - for (deque::const_iterator s = sections.begin(); s != sections.end(); ++s) { - my_sections.push_back(*s); + std::vector my_sections{sections.begin(), sections.end()}; + for (auto& section : g_conf().get_my_sections()) { + my_sections.push_back(section); } - g_conf().get_my_sections(my_sections); std::string val; int ret = g_conf().get_val_from_conf_file(my_sections, key.c_str(), val, true); if (ret == -ENOENT)