Skip to content

Commit

Permalink
attempt to simplify the plink ref
Browse files Browse the repository at this point in the history
  • Loading branch information
oranagra authored and huangzhw committed Sep 6, 2021
1 parent dc4694e commit 9226d4e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/dict.c
Expand Up @@ -548,7 +548,6 @@ void *dictFetchValue(dict *d, const void *key) {
*/
dictEntry *dictFindWithPlink(dict *d, const void *key, dictEntry ***plink, int *table_index)
{
dictEntry *he, *prevHe;
uint64_t h, idx, table;

if (dictSize(d) == 0) return NULL; /* dict is empty */
Expand All @@ -557,17 +556,14 @@ dictEntry *dictFindWithPlink(dict *d, const void *key, dictEntry ***plink, int *

for (table = 0; table <= 1; table++) {
idx = h & DICTHT_SIZE_MASK(d->ht_size_exp[table]);
he = d->ht_table[table][idx];
prevHe = NULL;
while(he) {
if (key==he->key || dictCompareKeys(d, key, he->key)) {
if (prevHe) *plink = &prevHe->next;
else *plink = &d->ht_table[table][idx];
dictEntry **ref = &d->ht_table[table][idx];
while(*ref) {
if (key==(*ref)->key || dictCompareKeys(d, key, (*ref)->key)) {
*table_index = table;
return he;
*plink = ref;
return *ref;
}
prevHe = he;
he = he->next;
ref = &(*ref)->next;
}
if (!dictIsRehashing(d)) return NULL;
}
Expand Down

0 comments on commit 9226d4e

Please sign in to comment.