From 65fa1c1e642f2a0620c11c2a1553105604652352 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 4 Jan 2021 17:22:09 +0800 Subject: [PATCH] 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 --- src/common/ConfUtils.cc | 2 +- src/common/ConfUtils.h | 6 +++--- src/common/config.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/ConfUtils.cc b/src/common/ConfUtils.cc index 6231c7a7a3da..d1ed75cea519 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 8e739a516eda..5252b62028df 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 1815c9ff4e7f..b110e9977271 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) { -- 2.47.3