summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2019-05-22 17:36:11 +0300
committerPranith Kumar Karampuri <pkarampu@redhat.com>2019-11-05 06:25:24 +0000
commit28199dc009869858bcea108f116ce10c06358e03 (patch)
tree17667b3ae10b856e8b9fa5418d3ab2ee11bd44f5
parent3ab23415804502b1ba89360c55ac3e8143822a0b (diff)
dict.c: remove one strlen() done under lock.
It's not needed in some cases, where we can pass the key length. Change-Id: I2e8ed0b69c50a35f5858bae7c1755a0dfd2c77e5 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
-rw-r--r--libglusterfs/src/dict.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index b790c93..ff49dc7 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -382,8 +382,8 @@ dict_lookup(dict_t *this, char *key, data_t **data)
}
static int32_t
-dict_set_lk(dict_t *this, char *key, data_t *value, const uint32_t hash,
- gf_boolean_t replace)
+dict_set_lk(dict_t *this, char *key, const int key_len, data_t *value,
+ const uint32_t hash, gf_boolean_t replace)
{
int hashval = 0;
data_pair_t *pair;
@@ -399,7 +399,7 @@ dict_set_lk(dict_t *this, char *key, data_t *value, const uint32_t hash,
key_free = 1;
key_hash = (uint32_t)XXH64(key, keylen, 0);
} else {
- keylen = strlen(key);
+ keylen = key_len;
key_hash = hash;
}
@@ -496,12 +496,12 @@ dict_setn(dict_t *this, char *key, const int keylen, data_t *value)
}
if (key) {
- key_hash = (int32_t)XXH64(key, keylen, 0);
+ key_hash = (uint32_t)XXH64(key, keylen, 0);
}
LOCK(&this->lock);
- ret = dict_set_lk(this, key, value, key_hash, 1);
+ ret = dict_set_lk(this, key, keylen, value, key_hash, 1);
UNLOCK(&this->lock);
@@ -535,7 +535,7 @@ dict_addn(dict_t *this, char *key, const int keylen, data_t *value)
LOCK(&this->lock);
- ret = dict_set_lk(this, key, value, key_hash, 0);
+ ret = dict_set_lk(this, key, keylen, value, key_hash, 0);
UNLOCK(&this->lock);
@@ -2079,7 +2079,7 @@ _dict_modify_flag(dict_t *this, char *key, int flag, int op)
*/
GF_ASSERT(flag >= 0 && flag < DICT_MAX_FLAGS);
- hash = (int32_t)XXH64(key, strlen(key), 0);
+ hash = (uint32_t)XXH64(key, strlen(key), 0);
LOCK(&this->lock);
{
pair = dict_lookup_common(this, key, hash);
@@ -2807,6 +2807,7 @@ dict_rename_key(dict_t *this, char *key, char *replace_key)
int ret = -EINVAL;
uint32_t hash;
uint32_t replacekey_hash;
+ int replacekey_len;
/* replacing a key by itself is a NO-OP */
if (strcmp(key, replace_key) == 0)
@@ -2819,7 +2820,8 @@ dict_rename_key(dict_t *this, char *key, char *replace_key)
}
hash = (uint32_t)XXH64(key, strlen(key), 0);
- replacekey_hash = (uint32_t)XXH64(replace_key, strlen(replace_key), 0);
+ replacekey_len = strlen(replace_key);
+ replacekey_hash = (uint32_t)XXH64(replace_key, replacekey_len, 0);
LOCK(&this->lock);
{
@@ -2828,8 +2830,8 @@ dict_rename_key(dict_t *this, char *key, char *replace_key)
if (!pair)
ret = -ENODATA;
else
- ret = dict_set_lk(this, replace_key, pair->value, replacekey_hash,
- 1);
+ ret = dict_set_lk(this, replace_key, replacekey_len, pair->value,
+ replacekey_hash, 1);
}
UNLOCK(&this->lock);