summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-06-26 10:49:46 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-06-30 14:34:35 +0200
commite1fbee0071ad6bb5d5c17865c5a7b67a63930e7d (patch)
treee65b02be9d362e98aa32ad994c31465c94b341ee /src
parentb8b6830dfd75f6870b2171e7f31cb0cdb927532e (diff)
downloadcalcurse-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>
Diffstat (limited to 'src')
-rw-r--r--src/llist.c39
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;