summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/dict.h
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-17 22:29:05 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-27 13:15:05 +0000
commitb76a84be697074e4132120200320671d87f815ae (patch)
treefb85afef0306622e0e70851ef0f61f0e4451a91d /libglusterfs/src/dict.h
parentc416327b31d4a5dad619007c13c3e9a06e3cd398 (diff)
libglusterfs/src/dict.{c,h}: Introduce dict_setn, dict_addn, dict_addn and others.
They all take as a parameter the key length, instead of strlen() it. In most cases, we know the key length, we just never bothered to save and pass it along. (We most likely sprintf'ed it earlier and the return value could have been used). A more interesting addition is dict_set_nstrn() [horrible name. Ideas are welcome]. It accepts both the string length and the key length and avoids strlen() both. Some of it can be calculated on compile-time, btw. For example: dict_set_str (dict, "key", "all"); Should become: dict_set_nstrn (dict, "key", sizeof ("key"), "all", sizeof ("all")); Compile-tested only! Change-Id: Ic2667f445f6c2e22e279505f5ad435788b4b668c updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'libglusterfs/src/dict.h')
-rw-r--r--libglusterfs/src/dict.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index 4c204d6c037..83cfd9c0827 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -110,12 +110,16 @@ void data_destroy (data_t *data);
/* function to set a key/value pair (overwrite existing if matches the key */
int32_t dict_set (dict_t *this, char *key, data_t *value);
+int32_t dict_setn (dict_t *this, char *key, const int keylen, data_t *value);
/* function to set a new key/value pair (without checking for duplicate) */
int32_t dict_add (dict_t *this, char *key, data_t *value);
-
+int32_t dict_addn (dict_t *this, char *key, const int keylen, data_t *value);
int dict_get_with_ref (dict_t *this, char *key, data_t **data);
+int dict_get_with_refn (dict_t *this, char *key, const int keylen, data_t **data);
data_t *dict_get (dict_t *this, char *key);
+data_t *dict_getn (dict_t *this, char *key, const int keylen);
void dict_del (dict_t *this, char *key);
+void dict_deln (dict_t *this, char *key, const int keylen);
int dict_reset (dict_t *dict);
int dict_key_count (dict_t *this);
@@ -137,7 +141,7 @@ int32_t dict_lookup (dict_t *this, char *key, data_t **data);
*/
data_t *int_to_data (int64_t value);
data_t *str_to_data (char *value);
-data_t *data_from_dynstr (char *value);
+data_t *strn_to_data (char *value, const int vallen);
data_t *data_from_dynptr (void *value, int32_t len);
data_t *bin_to_data (void *value, int32_t len);
data_t *static_str_to_data (char *value);
@@ -250,10 +254,14 @@ GF_MUST_CHECK int dict_set_static_bin (dict_t *this, char *key, void *ptr, size_
GF_MUST_CHECK int dict_set_option (dict_t *this, char *key, char *str);
GF_MUST_CHECK int dict_set_str (dict_t *this, char *key, char *str);
+GF_MUST_CHECK int dict_set_strn (dict_t *this, char *key, const int keylen, char *str);
+GF_MUST_CHECK int dict_set_nstrn (dict_t *this, char *key, const int keylen, char *str, const int vallen);
GF_MUST_CHECK int dict_set_dynstr (dict_t *this, char *key, char *str);
+GF_MUST_CHECK int dict_set_dynstrn (dict_t *this, char *key, const int keylen, char *str);
GF_MUST_CHECK int dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str);
GF_MUST_CHECK int dict_add_dynstr_with_alloc (dict_t *this, char *key, char *str);
GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str);
+GF_MUST_CHECK int dict_get_strn (dict_t *this, char *key, const int keylen, char **str);
GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val);
GF_MUST_CHECK int dict_rename_key (dict_t *this, char *key, char *replace_key);