Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/evas
Dir : e17/libs/evas/src/lib/data
Modified Files:
evas_list.c
Log Message:
1. id3 album cover loader patches
2. i reduced list note memory usage by 20% - shoudl work better with malloc
as ti is now a power of 2 as well
3. optimised evas internals to make use of event freezes to make e17'sw menu
popups a LOT snappier
4. fixed using last member of list nodes - bad - shoudl use api as this is
private stuff really
5. added config profile stuff to e17 u can literally maintain multiple
config profiles and choose which one at any time etc.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/data/evas_list.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- evas_list.c 18 Jun 2005 01:00:30 -0000 1.15
+++ evas_list.c 22 Jul 2005 10:28:10 -0000 1.16
@@ -4,6 +4,14 @@
#include "evas_common.h"
#include "evas_private.h"
+typedef struct _Evas_List_Accounting Evas_List_Accounting;
+
+struct _Evas_List_Accounting
+{
+ Evas_List *last;
+ int count;
+};
+
static int _evas_list_alloc_error = 0;
/**
@@ -51,37 +59,27 @@
return list;
}
new_l->next = NULL;
- new_l->prev = NULL;
new_l->data = (void *)data;
if (!list)
{
- new_l->last = new_l;
- new_l->count = 1;
- return new_l;
- }
- if (list->last)
- {
- l = list->last;
- l->next = new_l;
- new_l->prev = l;
- list->last = new_l;
- list->count++;
- return list;
- }
- else
- {
- for (l = list; l; l = l->next)
+ new_l->prev = NULL;
+ new_l->accounting = malloc(sizeof(Evas_List_Accounting));
+ if (!new_l->accounting)
{
- if (!l->next)
- {
- l->next = new_l;
- new_l->prev = l;
- list->last = new_l;
- list->count++;
- return list;
- }
+ _evas_list_alloc_error = 1;
+ free(new_l);
+ return list;
}
+ ((Evas_List_Accounting *)(new_l->accounting))->last = new_l;
+ ((Evas_List_Accounting *)(new_l->accounting))->count = 1;
+ return new_l;
}
+ l = ((Evas_List_Accounting *)(list->accounting))->last;
+ l->next = new_l;
+ new_l->prev = l;
+ new_l->accounting = list->accounting;
+ ((Evas_List_Accounting *)(list->accounting))->last = new_l;
+ ((Evas_List_Accounting *)(list->accounting))->count++;
return list;
}
@@ -128,15 +126,21 @@
if (!list)
{
new_l->next = NULL;
- new_l->last = new_l;
- new_l->count = 1;
+ new_l->accounting = malloc(sizeof(Evas_List_Accounting));
+ if (!new_l->accounting)
+ {
+ _evas_list_alloc_error = 1;
+ free(new_l);
+ return list;
+ }
+ ((Evas_List_Accounting *)(new_l->accounting))->last = new_l;
+ ((Evas_List_Accounting *)(new_l->accounting))->count = 1;
return new_l;
}
new_l->next = list;
list->prev = new_l;
- new_l->last = list->last;
- list->last = NULL;
- new_l->count = list->count + 1;
+ new_l->accounting = list->accounting;
+ ((Evas_List_Accounting *)(list->accounting))->count++;
return new_l;
}
@@ -206,8 +210,10 @@
l->next = new_l;
new_l->prev = l;
- if (!new_l->next) list->last = new_l;
- list->count++;
+ new_l->accounting = list->accounting;
+ ((Evas_List_Accounting *)(list->accounting))->count++;
+ if (!new_l->next)
+ ((Evas_List_Accounting *)(new_l->accounting))->last = new_l;
return list;
}
}
@@ -281,19 +287,12 @@
new_l->next = l;
if (l->prev) l->prev->next = new_l;
l->prev = new_l;
+ new_l->accounting = list->accounting;
+ ((Evas_List_Accounting *)(list->accounting))->count++;
if (new_l->prev)
- {
- if (!new_l->next) list->last = new_l;
- list->count++;
- return list;
- }
+ return list;
else
- {
- new_l->last = list->last;
- list->last = NULL;
- new_l->count = list->count + 1;
- return new_l;
- }
+ return new_l;
}
}
return evas_list_prepend(list, data);
@@ -362,6 +361,7 @@
{
Evas_List *return_l;
+ if (!list) return NULL;
if (!remove_list) return list;
if (remove_list->next) remove_list->next->prev = remove_list->prev;
if (remove_list->prev)
@@ -370,15 +370,13 @@
return_l = list;
}
else
- {
- if (remove_list->next)
- remove_list->next->count = remove_list->count;
- return_l = remove_list->next;
- if (return_l) return_l->last = list->last;
- }
- if (remove_list == list->last) list->last = remove_list->prev;
+ return_l = remove_list->next;
+ if (remove_list == ((Evas_List_Accounting *)(list->accounting))->last)
+ ((Evas_List_Accounting *)(list->accounting))->last = remove_list->prev;
+ ((Evas_List_Accounting *)(list->accounting))->count--;
+ if (((Evas_List_Accounting *)(list->accounting))->count == 0)
+ free(list->accounting);
free(remove_list);
- if (return_l) return_l->count--;
return return_l;
}
@@ -479,6 +477,8 @@
{
Evas_List *l, *free_l;
+ if (!list) return NULL;
+ free(list->accounting);
for (l = list; l;)
{
free_l = l;
@@ -523,7 +523,7 @@
evas_list_last(Evas_List *list)
{
if (!list) return NULL;
- return list->last;
+ return ((Evas_List_Accounting *)(list->accounting))->last;
}
/**
@@ -640,7 +640,7 @@
evas_list_count(Evas_List *list)
{
if (!list) return 0;
- return list->count;
+ return ((Evas_List_Accounting *)(list->accounting))->count;
}
/**
@@ -668,8 +668,9 @@
void *
evas_list_nth(Evas_List *list, int n)
{
- Evas_List *l = evas_list_nth_list(list, n);
-
+ Evas_List *l;
+
+ l = evas_list_nth_list(list, n);
return l ? l->data : NULL;
}
@@ -702,14 +703,19 @@
Evas_List *l;
/* check for non-existing nodes */
- if ((!list) || (n < 0) || (n > list->count - 1)) return NULL;
+ if ((!list) || (n < 0) ||
+ (n > ((Evas_List_Accounting *)(list->accounting))->count - 1))
+ return NULL;
/* if the node is in the 2nd half of the list, search from the end
* else, search from the beginning.
*/
- if (n > list->count / 2)
+ if (n > (((Evas_List_Accounting *)(list->accounting))->count / 2))
{
- for (i = list->count - 1, l = list->last; l; l = l->prev, i--)
+ for (i = ((Evas_List_Accounting *)(list->accounting))->count - 1,
+ l = ((Evas_List_Accounting *)(list->accounting))->last;
+ l;
+ l = l->prev, i--)
{
if (i == n) return l;
}
@@ -753,7 +759,7 @@
if (!list) return NULL;
l1 = list;
- l2 = list->last;
+ l2 = ((Evas_List_Accounting *)(list->accounting))->last;
while (l1 != l2)
{
void *data;
@@ -859,31 +865,36 @@
Evas_List *
evas_list_sort(Evas_List *list, int size, int (*func)(void *, void *))
{
- Evas_List *l = NULL, *ll = NULL;
+ Evas_List *l = NULL, *ll = NULL, *llast;
int mid;
if (!list || !func)
return NULL;
+ /* FIXME: this is really inefficient - calling evas_list_nth is not
+ * fast as it has to walk the list */
+
/* if the caller specified an invalid size, sort the whole list */
- if (size <= 0 || size > list->count)
- size = list->count;
+ if ((size <= 0) ||
+ (size > ((Evas_List_Accounting *)(list->accounting))->count))
+ size = ((Evas_List_Accounting *)(list->accounting))->count;
mid = size / 2;
- if (mid < 1)
- return list;
+ if (mid < 1) return list;
/* bleh evas list splicing */
+ llast = ((Evas_List_Accounting *)(list->accounting))->last;
ll = evas_list_nth_list(list, mid);
if (ll->prev)
{
- list->last = ll->prev;
- list->count = mid;
+ ((Evas_List_Accounting *)(list->accounting))->last = ll->prev;
+ ((Evas_List_Accounting *)(list->accounting))->count = mid;
ll->prev->next = NULL;
ll->prev = NULL;
}
-
- ll->count = size - mid;
+ ll->accounting = malloc(sizeof(Evas_List_Accounting));
+ ((Evas_List_Accounting *)(ll->accounting))->last = llast;
+ ((Evas_List_Accounting *)(ll->accounting))->count = size - mid;
/* merge sort */
l = evas_list_sort(list, mid, func);
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs