mirror of
https://github.com/fluencelabs/redis
synced 2025-06-27 07:51:33 +00:00
various cleanups and minor fixes
This commit is contained in:
18
src/adlist.c
18
src/adlist.c
@ -242,7 +242,7 @@ listNode *listNext(listIter *iter)
|
||||
list *listDup(list *orig)
|
||||
{
|
||||
list *copy;
|
||||
listIter *iter;
|
||||
listIter iter;
|
||||
listNode *node;
|
||||
|
||||
if ((copy = listCreate()) == NULL)
|
||||
@ -250,26 +250,23 @@ list *listDup(list *orig)
|
||||
copy->dup = orig->dup;
|
||||
copy->free = orig->free;
|
||||
copy->match = orig->match;
|
||||
iter = listGetIterator(orig, AL_START_HEAD);
|
||||
while((node = listNext(iter)) != NULL) {
|
||||
listRewind(orig, &iter);
|
||||
while((node = listNext(&iter)) != NULL) {
|
||||
void *value;
|
||||
|
||||
if (copy->dup) {
|
||||
value = copy->dup(node->value);
|
||||
if (value == NULL) {
|
||||
listRelease(copy);
|
||||
listReleaseIterator(iter);
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
value = node->value;
|
||||
if (listAddNodeTail(copy, value) == NULL) {
|
||||
listRelease(copy);
|
||||
listReleaseIterator(iter);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
listReleaseIterator(iter);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -284,24 +281,21 @@ list *listDup(list *orig)
|
||||
* NULL is returned. */
|
||||
listNode *listSearchKey(list *list, void *key)
|
||||
{
|
||||
listIter *iter;
|
||||
listIter iter;
|
||||
listNode *node;
|
||||
|
||||
iter = listGetIterator(list, AL_START_HEAD);
|
||||
while((node = listNext(iter)) != NULL) {
|
||||
listRewind(list, &iter);
|
||||
while((node = listNext(&iter)) != NULL) {
|
||||
if (list->match) {
|
||||
if (list->match(node->value, key)) {
|
||||
listReleaseIterator(iter);
|
||||
return node;
|
||||
}
|
||||
} else {
|
||||
if (key == node->value) {
|
||||
listReleaseIterator(iter);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
listReleaseIterator(iter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user