]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: let get_my_sections() return the section names
authorKefu Chai <kchai@redhat.com>
Wed, 29 Jul 2020 10:17:23 +0000 (18:17 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 1 Aug 2020 16:01:47 +0000 (00:01 +0800)
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 <kchai@redhat.com>
src/ceph_mon.cc
src/common/config.cc
src/common/config.h
src/common/config_proxy.h
src/tools/ceph_conf.cc

index 3bd219f11074aaab634bbd7fa4fccab0091ccbe1..25c641e9ad3bfedcf68cc749d37cf6eabd658666 100644 (file)
@@ -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 <std::string> my_sections;
-    g_conf().get_my_sections(my_sections);
+    std::vector<std::string> 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) {
index 3f7fe25181e172a9355d046606caab61a9c813e6..f53d453825f73c7664b64e369d18ccd4abf9ba6d 100644 (file)
@@ -396,8 +396,7 @@ int md_config_t::parse_config_files(ConfigValues& values,
     }
   }
 
-  std::vector <std::string> my_sections;
-  _get_my_sections(values, my_sections);
+  std::vector<std::string> 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<std::string> *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 <std::string> &sections) const
+std::vector <std::string>
+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 <std::string> &sections) 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
index d1f3dac2d42f7faf842c7fdb48a483b7dd8e1534..0fa89382b8a25258c43da56e2d9a729abb5dd892 100644 (file)
@@ -205,8 +205,7 @@ public:
   void get_all_keys(std::vector<std::string> *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 <std::string> &sections) const;
+  std::vector<std::string> get_my_sections(const ConfigValues& values) const;
 
   // Return a list of all sections
   int get_all_sections(std::vector <std::string> &sections) 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<std::string> &sections) const;
-
   int _get_val_from_conf_file(const std::vector<std::string> &sections,
                              const std::string_view key, std::string &out) const;
 
index 9c0850fd08e1c7053f72e411c06d548e070aec06..f66e7c410e6acd5d995540f81b216f6a8e625923 100644 (file)
@@ -170,9 +170,9 @@ public:
     std::lock_guard l{lock};
     return config.diff(values, f, name);
   }
-  void get_my_sections(std::vector <std::string> &sections) const {
+  std::vector<std::string> 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<std::string>& sections) const {
     std::lock_guard l{lock};
index a86d436ae9aef2227b364efe6900f65fbf124a30..df5384a9e91d05a32ee7c4732a79187f09993aae 100644 (file)
@@ -117,11 +117,10 @@ static int list_sections(const std::string &prefix,
 static int lookup(const std::deque<std::string> &sections,
                  const std::string &key, bool resolve_search)
 {
-  std::vector <std::string> my_sections;
-  for (deque<string>::const_iterator s = sections.begin(); s != sections.end(); ++s) {
-    my_sections.push_back(*s);
+  std::vector<std::string> 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)