All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sahithi R V <sahithi.rv1@gmail.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH]common/str_map: Removed unnecessary function overloading of get_str_map()
Date: Wed, 27 Jan 2016 11:53:51 +0530	[thread overview]
Message-ID: <CAAKF69rJmAA2rNaFjDetkN5-1uQf+UZXhmD9xXx+89-S0goE4g@mail.gmail.com> (raw)

Hello,

This patch removes the function overloading of get_str_map() by using
CONST_DELIMS as default parameters to const char *delims .It also
replaces all the occurences of get_str_map() function with 2
arguments, in src directory.

Signed-off-by: Sahithi R V <sahithi.rv1@gmail.com>
---
 src/common/str_map.cc           | 14 +++-----------
 src/include/str_map.h           | 10 ++++------
 src/kv/RocksDBStore.cc          |  2 +-
 src/test/common/test_str_map.cc |  2 +-
 4 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/common/str_map.cc b/src/common/str_map.cc
index bd68612..4605302 100644
--- a/src/common/str_map.cc
+++ b/src/common/str_map.cc
@@ -51,7 +51,7 @@ int get_json_str_map(
   } catch (json_spirit::Error_position &e) {
     if (fallback_to_plain) {
       // fallback to key=value format
-      get_str_map(str, "\t\n ", str_map);
+      get_str_map(str, str_map, "\t\n ");
     } else {
       return -EINVAL;
     }
@@ -75,8 +75,8 @@ string trim(const string& str) {

 int get_str_map(
     const string &str,
-    const char *delims,
-    map<string,string> *str_map)
+    map<string,string> *str_map,
+    const char *delims)
 {
   list<string> pairs;
   get_str_list(str, delims, pairs);
@@ -94,14 +94,6 @@ int get_str_map(
   return 0;
 }

-int get_str_map(
-    const string &str,
-    map<string,string> *str_map)
-{
-  const char *delims = ",;\t\n ";
-  return get_str_map(str, delims, str_map);
-}
-
 string get_str_map_value(
     const map<string,string> &str_map,
     const string &key,
diff --git a/src/include/str_map.h b/src/include/str_map.h
index 0bd9de3..6a0370d 100644
--- a/src/include/str_map.h
+++ b/src/include/str_map.h
@@ -17,6 +17,8 @@
 #ifndef CEPH_STRMAP_H
 #define CEPH_STRMAP_H

+#define CONST_DELIMS ",;\t\n "
+
 #include <map>
 #include <string>
 #include <sstream>
@@ -89,12 +91,8 @@ extern int get_json_str_map(
  */
 extern int get_str_map(
     const std::string &str,
-    const char *delims,
-    std::map<std::string,std::string> *str_map);
-
-extern int get_str_map(
-    const std::string &str,
-    std::map<std::string,std::string> *str_map);
+    std::map<std::string,std::string> *str_map,
+    const char *delims = CONST_DELIMS);

 /**
  * Returns the value of **key** in **str_map** if available.
diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc
index 794a254..41caee0 100644
--- a/src/kv/RocksDBStore.cc
+++ b/src/kv/RocksDBStore.cc
@@ -118,7 +118,7 @@ int RocksDBStore::tryInterpret(const string key,
const string val, rocksdb::Opti
 int RocksDBStore::ParseOptionsFromString(const string opt_str,
rocksdb::Options &opt)
 {
   map<string, string> str_map;
-  int r = get_str_map(opt_str, ",\n;", &str_map);
+  int r = get_str_map(opt_str, &str_map, ",\n;");
   if (r < 0)
     return r;
   map<string, string>::iterator it;
diff --git a/src/test/common/test_str_map.cc b/src/test/common/test_str_map.cc
index 5a324ba..e96c792 100644
--- a/src/test/common/test_str_map.cc
+++ b/src/test/common/test_str_map.cc
@@ -58,7 +58,7 @@ TEST(str_map, plaintext) {
   }
   {
     map<string,string> str_map;
-    ASSERT_EQ(0, get_str_map(" key1=val1; key2=\tval2; key3\t = \t
val3; \n ", "\n;", &str_map));
+    ASSERT_EQ(0, get_str_map(" key1=val1; key2=\tval2; key3\t = \t
val3; \n ", &str_map, "\n;"));
     ASSERT_EQ(4u, str_map.size());
     ASSERT_EQ("val1", str_map["key1"]);
     ASSERT_EQ("val2", str_map["key2"]);
-- 
1.9.1

             reply	other threads:[~2016-01-27  6:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27  6:23 Sahithi R V [this message]
2016-01-27  9:43 ` [PATCH]common/str_map: Removed unnecessary function overloading of get_str_map() Ilya Dryomov
2016-01-27 11:07   ` Sahithi R V
2016-01-27 13:55     ` Sage Weil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAKF69rJmAA2rNaFjDetkN5-1uQf+UZXhmD9xXx+89-S0goE4g@mail.gmail.com \
    --to=sahithi.rv1@gmail.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.