From: Kefu Chai Date: Mon, 4 Jan 2021 09:22:09 +0000 (+0800) Subject: common/ConfUtils: pass string_view instead of string X-Git-Tag: v17.0.0~149^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=65fa1c1e642f2a0620c11c2a1553105604652352;p=ceph.git common/ConfUtils: pass string_view instead of string 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 --- diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index 6231c7a7a3da5..d1ed75cea5197 100644 --- a/src/common/ConfUtils.cc +++ b/src/common/ConfUtils.cc @@ -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 { diff --git a/src/common/ConfUtils.h b/src/common/ConfUtils.h index 8e739a516edac..5252b62028df2 100644 --- a/src/common/ConfUtils.h +++ b/src/common/ConfUtils.h @@ -58,8 +58,8 @@ public: friend std::ostream& operator<<(std::ostream& os, const conf_section_t&); }; -class ConfFile : public std::map { - using base_type = std::map; +class ConfFile : public std::map> { + using base_type = std::map>; public: ConfFile() : ConfFile{std::vector{}} @@ -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 diff --git a/src/common/config.cc b/src/common/config.cc index 1815c9ff4e7f3..b110e99772715 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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) {