changeset 106:06c968b92090

Use pointer to pointer in array_find, better to reuse
author David Demelier <markand@malikania.fr>
date Sat, 28 Jan 2012 19:38:59 +0100
parents eac1f370910a
children 2b2cb686e358
files array.c
diffstat 1 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/array.c	Tue Jan 24 16:26:25 2012 +0100
+++ b/array.c	Sat Jan 28 19:38:59 2012 +0100
@@ -271,25 +271,24 @@
 
 /*
  * Compare each object with the user supplied function. If the `fn' function
- * returns 1 then the index of the data position is returned and the parameter
- * data is filled with the array data at the correct index. If the comparison
- * function nevers returns 1, array_find returns -1.
+ * returns 1, 1 is returned and dst points to the correct object, dst should
+ * be a pointer to a pointer of object, like (int **) for a array of int.
  */
 
 int
-array_find(const struct array *arr, array_cmp_fn fn, void *data, void *u)
+array_find(const struct array *arr, array_cmp_fn fn, void *dst, void *u)
 {
 	int st, i;
 
-	for (i = st = 0; i < arr->length && st != 1; ++i)
+	for (i = st = 0; i < arr->length && !st; ++i)
 		st = fn((char *)arr->data + OFFSET(i), u);
 
 	if (st)
-		memcpy(data, (char *)arr->data + OFFSET(--i), arr->unit);
+		*(char **)dst = (char *)arr->data + OFFSET(--i);
 	else
-		i = -1;
+		st = 0;
 
-	return i;
+	return st;
 }
 
 /*