]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common,librbd: use string_view for keys of config
authorKefu Chai <kchai@redhat.com>
Thu, 21 Mar 2019 12:09:11 +0000 (20:09 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 22 Mar 2019 05:03:38 +0000 (13:03 +0800)
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 <kchai@redhat.com>
src/common/config.cc
src/common/config.h
src/librbd/api/Config.cc

index d0dc514de9cf34b22d5d047ec4c536e84367e2b2..aff3ff76a59116cb7ca2db04ad3a9b7c33ce7045 100644 (file)
@@ -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
index 527f6904e967cbc1b5ea235a93fc59b81259bfe6..2944ce1120fb1c239b93723a4edc3b6fbc75b876 100644 (file)
@@ -89,13 +89,13 @@ public:
   /*
    * Mapping from legacy config option names to class members
    */
-  std::map<std::string, member_ptr_t> legacy_values;
+  std::map<std::string_view, member_ptr_t> legacy_values;
 
   /**
    * The configuration schema, in the form of Option objects describing
    * possible settings.
    */
-  std::map<std::string, const Option&> schema;
+  std::map<std::string_view, const Option&> schema;
 
   /// values from mon that we failed to set
   std::map<std::string,std::string> ignored_mon_values;
index eec026f319110ee8b69dc5dcdc402aa1f3e8452d..3aa7573e8c22e1eef241bf8c615f5ce399251794 100644 (file)
@@ -21,9 +21,9 @@ namespace {
 
 const uint32_t MAX_KEYS = 64;
 
-typedef std::map<std::string, std::pair<std::string, config_source_t>> Parent;
+typedef std::map<std::string_view, std::pair<std::string, config_source_t>> Parent;
 
-static std::set<std::string> EXCLUDE_OPTIONS {
+static std::set<std::string_view> EXCLUDE_OPTIONS {
     "rbd_auto_exclusive_lock_until_manual_request",
     "rbd_default_format",
     "rbd_default_map_options",
@@ -36,7 +36,7 @@ static std::set<std::string> EXCLUDE_OPTIONS {
     "rbd_validate_pool",
     "rbd_mirror_pool_replayers_refresh_interval"
   };
-static std::set<std::string> EXCLUDE_IMAGE_OPTIONS {
+static std::set<std::string_view> 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<I>::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<I>::list(I *image_ctx, std::vector<config_option_t> *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<I>::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;
       }
     }
   }