mirror of
https://github.com/ceph/ceph
synced 2025-02-24 03:27:10 +00:00
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 <kchai@redhat.com>
This commit is contained in:
parent
d2d1c23a51
commit
65fa1c1e64
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user