From e1fbee0071ad6bb5d5c17865c5a7b67a63930e7d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 26 Jun 2012 10:49:46 +0200 Subject: 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 --- src/llist.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/llist.c b/src/llist.c index addce42..f771ef3 100644 --- a/src/llist.c +++ b/src/llist.c @@ -210,9 +210,16 @@ llist_item_t *llist_find_first(llist_t * l, void *data, { llist_item_t *i; - for (i = l->head; i; i = i->next) { - if (fn_match(i->data, data)) - return 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,9 +233,16 @@ llist_item_t *llist_find_next(llist_item_t * i, void *data, { if (i) { i = i->next; - for (; i; i = i->next) { - if (fn_match(i->data, data)) - return i; + 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; + } } } @@ -246,9 +260,16 @@ llist_item_t *llist_find_nth(llist_t * l, int n, void *data, if (n < 0) return NULL; - for (i = l->head; i; i = i->next) { - if (fn_match(i->data, data) && (n-- == 0)) - return i; + 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; -- cgit v1.2.3