From 756ed9ccbabc202027ab2c15f25f48483e800b86 Mon Sep 17 00:00:00 2001 From: Vivek Ellur Date: Thu, 14 May 2015 19:37:06 +0200 Subject: [PATCH] eina: fix eina_inarray_search to do linear search Summary: Currently eina_inarray_search was using binary search to search elements which would not work on unsorted array so modified it to work as linear search. There is already a function eina_inarray_search_sorted to work on sorted array. Signed-off-by: Vivek Ellur Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2501 Signed-off-by: Cedric BAIL --- src/lib/eina/eina_inarray.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/eina/eina_inarray.c b/src/lib/eina/eina_inarray.c index 2d52e6fd34..a216f0291b 100644 --- a/src/lib/eina/eina_inarray.c +++ b/src/lib/eina/eina_inarray.c @@ -150,12 +150,23 @@ _eina_inarray_get(const Eina_Inarray *array, unsigned int position) static int _eina_inarray_search(const Eina_Inarray *array, const void *data, Eina_Compare_Cb compare) { - const unsigned char *start, *found; - start = array->members; - found = bsearch(data, start, array->len, array->member_size, compare); - if (!found) + unsigned int found, pos=-1; + void *p; + + if (array->len == 0) + return -1; + + for (pos = 0; pos < array->len; ++pos) + { + p = _eina_inarray_get(array, pos); + found = compare(data, p); + if (found == 0) + break; + } + if (pos < array->len) + return pos; + else return -1; - return (found - start) / array->member_size; } static unsigned int