Enlightenment CVS committal
Author : tsauerbeck
Project : e17
Module : libs/evas
Dir : e17/libs/evas/src/lib/data
Modified Files:
evas_list.c
Log Message:
make evas_list_sort more bullet-proof
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/data/evas_list.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- evas_list.c 25 Feb 2005 15:15:41 -0000 1.11
+++ evas_list.c 25 Feb 2005 15:31:52 -0000 1.12
@@ -854,25 +854,36 @@
evas_list_sort(Evas_List *list, int size, int (*func)(void *, void *))
{
Evas_List *l = NULL, *ll = NULL;
- int range = (size / 2);
+ int mid;
+
+ if (!list || !func)
+ return NULL;
+
+ /* if the caller specified an invalid size, sort the whole list */
+ if (size <= 0 || size > list->count)
+ size = list->count;
+
+ mid = size / 2;
+ if (mid < 1)
+ return list;
+
+ /* bleh evas list splicing */
+ ll = evas_list_nth_list(list, mid);
+ if (ll->prev)
+ {
+ list->last = ll->prev;
+ list->count = mid;
+ ll->prev->next = NULL;
+ ll->prev = NULL;
+ }
+
+ ll->count = size - mid;
+
+ /* merge sort */
+ l = evas_list_sort(list, mid, func);
+ ll = evas_list_sort(ll, size - mid, func);
+ list = evas_list_combine(l, ll, func);
- if(range > 0)
- {
- /* bleh evas list splicing */
- ll = evas_list_nth_list(list, range);
- if(ll->prev)
- {
- list->last = ll->prev;
- list->count = range;
- }
- ll->prev->next = NULL;
- ll->count = size - range;
-
- /* merge sort */
- l = evas_list_sort(list, range, func);
- ll = evas_list_sort(ll, size - range, func);
- list = evas_list_combine(l, ll, func);
- }
return(list);
}
/**
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs