dict.c minor optimization

This commit is contained in:
Oran Agra 2016-04-25 16:48:25 +03:00
parent 7b52ef1da2
commit 6ed8c28230

View File

@ -424,7 +424,7 @@ static int dictGenericDelete(dict *d, const void *key, int nofree)
he = d->ht[table].table[idx]; he = d->ht[table].table[idx];
prevHe = NULL; prevHe = NULL;
while(he) { while(he) {
if (dictCompareKeys(d, key, he->key)) { if (key==he->key || dictCompareKeys(d, key, he->key)) {
/* Unlink the element from the list */ /* Unlink the element from the list */
if (prevHe) if (prevHe)
prevHe->next = he->next; prevHe->next = he->next;
@ -494,14 +494,14 @@ dictEntry *dictFind(dict *d, const void *key)
dictEntry *he; dictEntry *he;
unsigned int h, idx, table; unsigned int h, idx, table;
if (d->ht[0].size == 0) return NULL; /* We don't have a table at all */ if (d->ht[0].used + d->ht[1].used == 0) return NULL; /* dict is empty */
if (dictIsRehashing(d)) _dictRehashStep(d); if (dictIsRehashing(d)) _dictRehashStep(d);
h = dictHashKey(d, key); h = dictHashKey(d, key);
for (table = 0; table <= 1; table++) { for (table = 0; table <= 1; table++) {
idx = h & d->ht[table].sizemask; idx = h & d->ht[table].sizemask;
he = d->ht[table].table[idx]; he = d->ht[table].table[idx];
while(he) { while(he) {
if (dictCompareKeys(d, key, he->key)) if (key==he->key || dictCompareKeys(d, key, he->key))
return he; return he;
he = he->next; he = he->next;
} }
@ -981,7 +981,7 @@ static int _dictKeyIndex(dict *d, const void *key)
/* Search if this slot does not already contain the given key */ /* Search if this slot does not already contain the given key */
he = d->ht[table].table[idx]; he = d->ht[table].table[idx];
while(he) { while(he) {
if (dictCompareKeys(d, key, he->key)) if (key==he->key || dictCompareKeys(d, key, he->key))
return -1; return -1;
he = he->next; he = he->next;
} }