src/llist.c: Compare data pointers if callback is NULL
If a NULL callback is passed to llist_find_*(), fall back to comparing data pointers. The check for a NULL callback pointer is done outside the main loop with an eye towards performance. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
b8b6830dfd
commit
e1fbee0071
21
src/llist.c
21
src/llist.c
@ -210,10 +210,17 @@ llist_item_t *llist_find_first(llist_t * l, void *data,
|
||||
{
|
||||
llist_item_t *i;
|
||||
|
||||
if (fn_match) {
|
||||
for (i = l->head; i; i = i->next) {
|
||||
if (fn_match(i->data, data))
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
for (i = l->head; i; i = i->next) {
|
||||
if (i->data == data)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -226,10 +233,17 @@ llist_item_t *llist_find_next(llist_item_t * i, void *data,
|
||||
{
|
||||
if (i) {
|
||||
i = i->next;
|
||||
if (fn_match) {
|
||||
for (; i; i = i->next) {
|
||||
if (fn_match(i->data, data))
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
for (; i; i = i->next) {
|
||||
if (i->data == data)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -246,10 +260,17 @@ llist_item_t *llist_find_nth(llist_t * l, int n, void *data,
|
||||
if (n < 0)
|
||||
return NULL;
|
||||
|
||||
if (fn_match) {
|
||||
for (i = l->head; i; i = i->next) {
|
||||
if (fn_match(i->data, data) && (n-- == 0))
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
for (i = l->head; i; i = i->next) {
|
||||
if ((i->data == data) && (n-- == 0))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user