summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorPoornima Gurusiddaiah <pgurusid@redhat.com>2014-07-01 14:38:54 +0530
committerVijay Bellur <vbellur@redhat.com>2014-11-26 00:10:15 -0800
commit8f07191a4ab312c8b99e2eb08c7a1fc7e2c5eff2 (patch)
tree72d41add41e57a5186113febfc77201751183f5b /libglusterfs
parent8277f4e4a4e92543ac139ef63d0ad82add397de7 (diff)
dict: Remove the redundant hash calculation when the hash size is 1
Currently the dict is created with hash size 1, i.e. there is only one hash bucket and the calculation of hash decomes redundant. Change-Id: Id70aea0d798902494ebb6d82955d97d591bc73d2 BUG: 789278 Signed-off-by: Poornima Gurusiddaiah <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/8211 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra Talur <rtalur@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/dict.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index b8cb23fe700..3d8b5d8fef1 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -192,13 +192,19 @@ err_out:
static data_pair_t *
_dict_lookup (dict_t *this, char *key)
{
+ int hashval = 0;
if (!this || !key) {
gf_log_callingfn ("dict", GF_LOG_WARNING,
"!this || !key (%s)", key);
return NULL;
}
- int hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
+ /* If the divisor is 1, the modulo is always 0,
+ * in such case avoid hash calculation.
+ */
+ if (this->hash_size != 1)
+ hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
+
data_pair_t *pair;
for (pair = this->members[hashval]; pair != NULL; pair = pair->hash_next) {
@@ -235,7 +241,7 @@ dict_lookup (dict_t *this, char *key, data_t **data)
static int32_t
_dict_set (dict_t *this, char *key, data_t *value, gf_boolean_t replace)
{
- int hashval;
+ int hashval = 0;
data_pair_t *pair;
char key_free = 0;
int tmp = 0;
@@ -250,8 +256,13 @@ _dict_set (dict_t *this, char *key, data_t *value, gf_boolean_t replace)
key_free = 1;
}
- tmp = SuperFastHash (key, strlen (key));
- hashval = (tmp % this->hash_size);
+ /* If the divisor is 1, the modulo is always 0,
+ * in such case avoid hash calculation.
+ */
+ if (this->hash_size != 1) {
+ tmp = SuperFastHash (key, strlen (key));
+ hashval = (tmp % this->hash_size);
+ }
/* Search for a existing key if 'replace' is asked for */
if (replace) {
@@ -387,6 +398,8 @@ dict_get (dict_t *this, char *key)
void
dict_del (dict_t *this, char *key)
{
+ int hashval = 0;
+
if (!this || !key) {
gf_log_callingfn ("dict", GF_LOG_WARNING,
"!this || key=%s", key);
@@ -395,7 +408,12 @@ dict_del (dict_t *this, char *key)
LOCK (&this->lock);
- int hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
+ /* If the divisor is 1, the modulo is always 0,
+ * in such case avoid hash calculation.
+ */
+ if (this->hash_size != 1)
+ hashval = SuperFastHash (key, strlen (key)) % this->hash_size;
+
data_pair_t *pair = this->members[hashval];
data_pair_t *prev = NULL;