diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-06-26 10:49:46 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-06-30 14:34:35 +0200 |
commit | e1fbee0071ad6bb5d5c17865c5a7b67a63930e7d (patch) | |
tree | e65b02be9d362e98aa32ad994c31465c94b341ee | |
parent | b8b6830dfd75f6870b2171e7f31cb0cdb927532e (diff) | |
download | calcurse-e1fbee0071ad6bb5d5c17865c5a7b67a63930e7d.zip |
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>
-rw-r--r-- | src/llist.c | 39 |
1 files 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; |