From: Kefu Chai Date: Thu, 21 Mar 2019 12:09:11 +0000 (+0800) Subject: common,librbd: use string_view for keys of config X-Git-Tag: v15.0.0~115^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=81c5d20ad6b8382224992635877b7c15f5b36b30;p=ceph.git common,librbd: use string_view for keys of config the contained char sequences are either static char strings or strings in `Option` instances. so no need to keep another copy of string around. Signed-off-by: Kefu Chai --- diff --git a/src/common/config.cc b/src/common/config.cc index d0dc514de9c..aff3ff76a59 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -111,9 +111,7 @@ md_config_t::md_config_t(ConfigValues& values, << std::endl; ceph_abort(); } - schema.emplace(std::piecewise_construct, - std::forward_as_tuple(i.name), - std::forward_as_tuple(i)); + schema.emplace(i.name, i); } // Define the debug_* options as well. @@ -166,7 +164,7 @@ md_config_t::md_config_t(ConfigValues& values, // members if present. legacy_values = { #define OPTION(name, type) \ - {std::string(STRINGIFY(name)), &ConfigValues::name}, + {STRINGIFY(name), &ConfigValues::name}, #define SAFE_OPTION(name, type) OPTION(name, type) #include "common/legacy_config_opts.h" #undef OPTION diff --git a/src/common/config.h b/src/common/config.h index 527f6904e96..2944ce1120f 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -89,13 +89,13 @@ public: /* * Mapping from legacy config option names to class members */ - std::map legacy_values; + std::map legacy_values; /** * The configuration schema, in the form of Option objects describing * possible settings. */ - std::map schema; + std::map schema; /// values from mon that we failed to set std::map ignored_mon_values; diff --git a/src/librbd/api/Config.cc b/src/librbd/api/Config.cc index eec026f3191..3aa7573e8c2 100644 --- a/src/librbd/api/Config.cc +++ b/src/librbd/api/Config.cc @@ -21,9 +21,9 @@ namespace { const uint32_t MAX_KEYS = 64; -typedef std::map> Parent; +typedef std::map> Parent; -static std::set EXCLUDE_OPTIONS { +static std::set EXCLUDE_OPTIONS { "rbd_auto_exclusive_lock_until_manual_request", "rbd_default_format", "rbd_default_map_options", @@ -36,7 +36,7 @@ static std::set EXCLUDE_OPTIONS { "rbd_validate_pool", "rbd_mirror_pool_replayers_refresh_interval" }; -static std::set EXCLUDE_IMAGE_OPTIONS { +static std::set EXCLUDE_IMAGE_OPTIONS { "rbd_default_clone_format", "rbd_default_data_pool", "rbd_default_features", @@ -80,7 +80,7 @@ struct Options : Parent { CephContext *cct = (CephContext *)io_ctx.cct(); for (auto &it : *this) { - int r = cct->_conf.get_val(it.first.c_str(), &it.second.first); + int r = cct->_conf.get_val(std::string(it.first), &it.second.first); ceph_assert(r == 0); it.second.second = RBD_CONFIG_SOURCE_CONFIG; } @@ -141,8 +141,8 @@ int Config::list(librados::IoCtx& io_ctx, return r; } - for (auto &it : opts) { - options->push_back({it.first, it.second.first, it.second.second}); + for (auto& [k,v] : opts) { + options->push_back({std::string{k}, v.first, v.second}); } return 0; @@ -200,8 +200,8 @@ int Config::list(I *image_ctx, std::vector *options) { } } - for (auto &it : opts) { - options->push_back({it.first, it.second.first, it.second.second}); + for (auto& [k,v] : opts) { + options->push_back({std::string{k}, v.first, v.second}); } return 0; @@ -220,12 +220,12 @@ void Config::apply_pool_overrides(librados::IoCtx& io_ctx, return; } - for (auto& pair : opts) { - if (pair.second.second == RBD_CONFIG_SOURCE_POOL) { - r = config->set_val(pair.first, pair.second.first); + for (auto& [k,v] : opts) { + if (v.second == RBD_CONFIG_SOURCE_POOL) { + r = config->set_val(std::string(k), v.first); if (r < 0) { - lderr(cct) << "failed to override pool config " << pair.first << "=" - << pair.second.first << ": " << cpp_strerror(r) << dendl; + lderr(cct) << "failed to override pool config " << k << "=" + << v.first << ": " << cpp_strerror(r) << dendl; } } }