cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=756ed9ccbabc202027ab2c15f25f48483e800b86

commit 756ed9ccbabc202027ab2c15f25f48483e800b86
Author: Vivek Ellur <vivek.el...@samsung.com>
Date:   Thu May 14 19:37:06 2015 +0200

    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 <vivek.el...@samsung.com>
    
    Reviewers: cedric
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D2501
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 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 2d52e6f..a216f02 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

-- 


Reply via email to