]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ConfUtils: pass string_view instead of string 38754/head
authorKefu Chai <kchai@redhat.com>
Mon, 4 Jan 2021 09:22:09 +0000 (17:22 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 4 Jan 2021 09:29:58 +0000 (17:29 +0800)
pass string_view as the section_name when reading options from a
ConfFile. as there is no need to create a temporary string object
if the section name is a `const char*` literal.

also, update the caller site in `common/config.cc` accordingly as a
cleanup. as it's not necessary to pass a `const char*` for the section
name even without this change.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ConfUtils.cc
src/common/ConfUtils.h
src/common/config.cc

index 6231c7a7a3da573fece0d18a67517d1484d6521b..d1ed75cea51974066fa1f6a161a9b0f09aec1529 100644 (file)
@@ -282,7 +282,7 @@ int ConfFile::parse_bufferlist(ceph::bufferlist *bl,
   return parse_buffer({bl->c_str(), bl->length()}, warnings) ? 0 : -EINVAL;
 }
 
-int ConfFile::read(const std::string& section_name,
+int ConfFile::read(std::string_view section_name,
                   std::string_view key,
                   std::string &val) const
 {
index 8e739a516edac5f341ae123c0fd9313ee89c10f6..5252b62028df252ce982db7b83ea290c81da3948 100644 (file)
@@ -58,8 +58,8 @@ public:
   friend std::ostream& operator<<(std::ostream& os, const conf_section_t&);
 };
 
-class ConfFile : public std::map<std::string, conf_section_t> {
-  using base_type = std::map<std::string, conf_section_t>;
+class ConfFile : public std::map<std::string, conf_section_t, std::less<>> {
+  using base_type = std::map<std::string, conf_section_t, std::less<>>;
 public:
   ConfFile()
     : ConfFile{std::vector<conf_section_t>{}}
@@ -71,7 +71,7 @@ public:
   int parse_file(const std::string &fname, std::ostream *warnings);
   int parse_bufferlist(ceph::bufferlist *bl, std::ostream *warnings);
   bool parse_buffer(std::string_view buf, std::ostream* warning);
-  int read(const std::string& section, std::string_view key,
+  int read(std::string_view section, std::string_view key,
           std::string &val) const;
   static std::string normalize_key_name(std::string_view key);
   // print warnings to os if any old-style section name is found
index 1815c9ff4e7f365bc1cfead9ace79c7b84d0ec73..b110e99772715d059b03b8968e231a49246b2f53 100644 (file)
@@ -1368,7 +1368,7 @@ int md_config_t::_get_val_from_conf_file(
   std::string &out) const
 {
   for (auto &s : sections) {
-    int ret = cf.read(s.c_str(), std::string{key}, out);
+    int ret = cf.read(s, key, out);
     if (ret == 0) {
       return 0;
     } else if (ret != -ENOENT) {