]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/config_values: use string_view for keys
authorKefu Chai <kchai@redhat.com>
Fri, 22 Mar 2019 03:57:02 +0000 (11:57 +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_values.cc
src/common/config_values.h

index 24f556e35a22a5317221dcc5f35e2edab5b9e9b7..bc7fc8028a971490ee7738ad8dfbae4b8622d31e 100644 (file)
@@ -4,7 +4,7 @@
 #include "config.h"
 
 ConfigValues::set_value_result_t
-ConfigValues::set_value(const std::string& key,
+ConfigValues::set_value(const std::string_view key,
                         Option::value_t&& new_value,
                         int level)
 {  
@@ -30,7 +30,7 @@ ConfigValues::set_value(const std::string& key,
   }
 }
 
-int ConfigValues::rm_val(const std::string& key, int level)
+int ConfigValues::rm_val(const std::string_view key, int level)
 {
   auto i = values.find(key);
   if (i == values.end()) {
@@ -50,7 +50,7 @@ int ConfigValues::rm_val(const std::string& key, int level)
 }
 
 std::pair<Option::value_t, bool>
-ConfigValues::get_value(const std::string& name, int level) const
+ConfigValues::get_value(const std::string_view name, int level) const
 {
   auto p = values.find(name);
   if (p != values.end() && !p->second.empty()) {
@@ -78,7 +78,7 @@ void ConfigValues::set_logging(int which, const char* val)
   }
 }
 
-bool ConfigValues::contains(const std::string& key) const
+bool ConfigValues::contains(const std::string_view key) const
 {
   return values.count(key);
 }
index fdfff2b16f33eea5872411330d378507b3cf2541..fe7b36a40a78e72cf0b89edf788136c0e4f94235 100644 (file)
@@ -17,7 +17,7 @@
 // debug logging settings, and some other "unnamed" settings, like entity name of
 // the daemon.
 class ConfigValues {
-  using values_t = std::map<std::string, map<int32_t,Option::value_t>>;
+  using values_t = std::map<std::string_view, map<int32_t,Option::value_t>>;
   values_t values;
   // for populating md_config_impl::legacy_values in ctor
   friend struct md_config_t;
@@ -80,21 +80,21 @@ public:
   /**
    * @return true if changed, false otherwise
    */
-  set_value_result_t set_value(const std::string& key,
+  set_value_result_t set_value(std::string_view key,
                                Option::value_t&& value,
                                int level);
-  int rm_val(const std::string& key, int level);
+  int rm_val(const std::string_view key, int level);
   void set_logging(int which, const char* val);
   /**
    * @param level the level of the setting, -1 for the one with the 
    *              highest-priority
    */
-  std::pair<Option::value_t, bool> get_value(const std::string& name,
+  std::pair<Option::value_t, bool> get_value(const std::string_view name,
                                              int level) const;
   template<typename Func> void for_each(Func&& func) const {
     for (const auto& [name,configs] : values) {
       func(name, configs);
     }
   }
-  bool contains(const std::string& key) const;
+  bool contains(const std::string_view key) const;
 };