Stack allocate dict iterators
Replacing the get & release functions with an initiation function. Simplifies the code and will make sure we run subscription callbacks in OOM scenarios.
This commit is contained in:
parent
297ecbecb7
commit
920128a260
20
async.c
20
async.c
@ -306,7 +306,7 @@ static void __redisRunPushCallback(redisAsyncContext *ac, redisReply *reply) {
|
|||||||
static void __redisAsyncFree(redisAsyncContext *ac) {
|
static void __redisAsyncFree(redisAsyncContext *ac) {
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
redisCallback cb;
|
redisCallback cb;
|
||||||
dictIterator *it;
|
dictIterator it;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
|
|
||||||
/* Execute pending callbacks with NULL reply. */
|
/* Execute pending callbacks with NULL reply. */
|
||||||
@ -319,23 +319,17 @@ static void __redisAsyncFree(redisAsyncContext *ac) {
|
|||||||
|
|
||||||
/* Run subscription callbacks with NULL reply */
|
/* Run subscription callbacks with NULL reply */
|
||||||
if (ac->sub.channels) {
|
if (ac->sub.channels) {
|
||||||
it = dictGetIterator(ac->sub.channels);
|
dictInitIterator(&it,ac->sub.channels);
|
||||||
if (it != NULL) {
|
while ((de = dictNext(&it)) != NULL)
|
||||||
while ((de = dictNext(it)) != NULL)
|
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
||||||
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
|
||||||
dictReleaseIterator(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
dictRelease(ac->sub.channels);
|
dictRelease(ac->sub.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac->sub.patterns) {
|
if (ac->sub.patterns) {
|
||||||
it = dictGetIterator(ac->sub.patterns);
|
dictInitIterator(&it,ac->sub.patterns);
|
||||||
if (it != NULL) {
|
while ((de = dictNext(&it)) != NULL)
|
||||||
while ((de = dictNext(it)) != NULL)
|
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
||||||
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
|
||||||
dictReleaseIterator(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
dictRelease(ac->sub.patterns);
|
dictRelease(ac->sub.patterns);
|
||||||
}
|
}
|
||||||
|
11
dict.c
11
dict.c
@ -267,16 +267,11 @@ static dictEntry *dictFind(dict *ht, const void *key) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dictIterator *dictGetIterator(dict *ht) {
|
static void dictInitIterator(dictIterator *iter, dict *ht) {
|
||||||
dictIterator *iter = hi_malloc(sizeof(*iter));
|
|
||||||
if (iter == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
iter->ht = ht;
|
iter->ht = ht;
|
||||||
iter->index = -1;
|
iter->index = -1;
|
||||||
iter->entry = NULL;
|
iter->entry = NULL;
|
||||||
iter->nextEntry = NULL;
|
iter->nextEntry = NULL;
|
||||||
return iter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dictEntry *dictNext(dictIterator *iter) {
|
static dictEntry *dictNext(dictIterator *iter) {
|
||||||
@ -299,10 +294,6 @@ static dictEntry *dictNext(dictIterator *iter) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dictReleaseIterator(dictIterator *iter) {
|
|
||||||
hi_free(iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------- private functions ------------------------------ */
|
/* ------------------------- private functions ------------------------------ */
|
||||||
|
|
||||||
/* Expand the hash table if needed */
|
/* Expand the hash table if needed */
|
||||||
|
3
dict.h
3
dict.h
@ -119,8 +119,7 @@ static int dictReplace(dict *ht, void *key, void *val);
|
|||||||
static int dictDelete(dict *ht, const void *key);
|
static int dictDelete(dict *ht, const void *key);
|
||||||
static void dictRelease(dict *ht);
|
static void dictRelease(dict *ht);
|
||||||
static dictEntry * dictFind(dict *ht, const void *key);
|
static dictEntry * dictFind(dict *ht, const void *key);
|
||||||
static dictIterator *dictGetIterator(dict *ht);
|
static void dictInitIterator(dictIterator *iter, dict *ht);
|
||||||
static dictEntry *dictNext(dictIterator *iter);
|
static dictEntry *dictNext(dictIterator *iter);
|
||||||
static void dictReleaseIterator(dictIterator *iter);
|
|
||||||
|
|
||||||
#endif /* __DICT_H */
|
#endif /* __DICT_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user