Reduce code size, and improve sort speed.
SVN revision: 36382
This commit is contained in:
parent
dfdf20227b
commit
439401682d
|
@ -45,6 +45,8 @@ EAPI Eina_Inlist * eina_inlist_append_relative(Eina_Inlist *in_list, Eina_Inlist
|
|||
EAPI Eina_Inlist * eina_inlist_prepend_relative(Eina_Inlist *in_list, Eina_Inlist *in_item, Eina_Inlist *in_relative);
|
||||
EAPI Eina_Inlist * eina_inlist_remove(Eina_Inlist *in_list, Eina_Inlist *in_item);
|
||||
EAPI Eina_Inlist * eina_inlist_find(Eina_Inlist *in_list, Eina_Inlist *in_item);
|
||||
EAPI Eina_Inlist * eina_inlist_promote(Eina_Inlist *list, Eina_Inlist *item);
|
||||
EAPI Eina_Inlist * eina_inlist_demote(Eina_Inlist *list, Eina_Inlist *item);
|
||||
|
||||
EAPI Eina_Iterator *eina_inlist_iterator_new(const Eina_Inlist *in_list);
|
||||
EAPI Eina_Accessor *eina_inlist_accessor_new(const Eina_Inlist *in_list);
|
||||
|
|
|
@ -264,6 +264,65 @@ eina_inlist_remove(Eina_Inlist *list, Eina_Inlist *item)
|
|||
* FIXME: To be fixed
|
||||
*/
|
||||
EAPI Eina_Inlist *
|
||||
eina_inlist_promote(Eina_Inlist *list, Eina_Inlist *item)
|
||||
{
|
||||
if (item == list) return list;
|
||||
if (!item || !list) return list;
|
||||
|
||||
if (item->next)
|
||||
item->next->prev = item->prev;
|
||||
item->prev->next = item->next;
|
||||
|
||||
if (list->last == item)
|
||||
list->last = item->prev;
|
||||
|
||||
item->next = list;
|
||||
item->prev = NULL;
|
||||
item->last = list->last;
|
||||
|
||||
list->prev = item;
|
||||
list->last = NULL;
|
||||
|
||||
return item;
|
||||
}
|
||||
/**
|
||||
* To be documented
|
||||
* FIXME: To be fixed
|
||||
*/
|
||||
EAPI Eina_Inlist *
|
||||
eina_inlist_demote(Eina_Inlist *list, Eina_Inlist *item)
|
||||
{
|
||||
Eina_Inlist *l;
|
||||
|
||||
if (!item || !list) return list;
|
||||
if (list->last == item) return list;
|
||||
|
||||
if (!list->last)
|
||||
{
|
||||
for (l = list; l->next; l = l->next)
|
||||
;
|
||||
list->last = l;
|
||||
}
|
||||
|
||||
l = list;
|
||||
if (item->prev)
|
||||
item->prev->next = item->next;
|
||||
else
|
||||
l = item->next;
|
||||
item->next->prev = item->prev;
|
||||
|
||||
list->last->next = item;
|
||||
item->prev = list->last;
|
||||
item->next = NULL;
|
||||
|
||||
l->last = item;
|
||||
return l;
|
||||
}
|
||||
/**
|
||||
* To be documented
|
||||
* FIXME: To be fixed
|
||||
*/
|
||||
EAPI Eina_Inlist *
|
||||
eina_inlist_find(Eina_Inlist *list, Eina_Inlist *item)
|
||||
{
|
||||
Eina_Inlist *l;
|
||||
|
|
|
@ -335,10 +335,10 @@ eina_list_accessor_free(Eina_Accessor_List *it)
|
|||
MAGIC_FREE(it);
|
||||
}
|
||||
|
||||
static void
|
||||
static Eina_List *
|
||||
eina_list_sort_rebuild_prev(Eina_List *list)
|
||||
{
|
||||
Eina_List *prev = 0;
|
||||
Eina_List *prev = NULL;
|
||||
|
||||
EINA_MAGIC_CHECK_LIST(list);
|
||||
|
||||
|
@ -347,6 +347,8 @@ eina_list_sort_rebuild_prev(Eina_List *list)
|
|||
list->prev = prev;
|
||||
prev = list;
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
static Eina_List *
|
||||
|
@ -1263,10 +1265,7 @@ eina_list_sort(Eina_List *list, unsigned int size, Eina_Compare_Cb func)
|
|||
stack[i-1] = eina_list_sort_merge(stack[i-1], stack[i], func);
|
||||
|
||||
list = stack[0];
|
||||
eina_list_sort_rebuild_prev(list);
|
||||
|
||||
for (tail = list; tail->next; tail = tail->next)
|
||||
;
|
||||
tail = eina_list_sort_rebuild_prev(list);
|
||||
|
||||
if (unsort)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ struct _Chained_Pool
|
|||
int usage;
|
||||
};
|
||||
|
||||
static Chained_Pool *
|
||||
static inline Chained_Pool *
|
||||
_eina_chained_mp_pool_new(Chained_Mempool *pool)
|
||||
{
|
||||
Chained_Pool *p;
|
||||
|
@ -72,7 +72,7 @@ _eina_chained_mp_pool_new(Chained_Mempool *pool)
|
|||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
_eina_chained_mp_pool_free(Chained_Pool *p)
|
||||
{
|
||||
free(p);
|
||||
|
@ -91,8 +91,7 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
// base is not NULL - has a free slot
|
||||
if (p->base)
|
||||
{
|
||||
pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
|
||||
pool->first = eina_inlist_append(pool->first, EINA_INLIST_GET(p));
|
||||
pool->first = eina_inlist_demote(pool->first, EINA_INLIST_GET(p));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -109,10 +108,7 @@ eina_chained_mempool_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
p->base = *((void **)mem);
|
||||
// move to end - it just filled up
|
||||
if (!p->base)
|
||||
{
|
||||
pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
|
||||
pool->first = eina_inlist_append(pool->first, EINA_INLIST_GET(p));
|
||||
}
|
||||
pool->first = eina_inlist_demote(pool->first, EINA_INLIST_GET(p));
|
||||
p->usage++;
|
||||
pool->usage++;
|
||||
return mem;
|
||||
|
@ -143,13 +139,17 @@ eina_chained_mempool_free(void *data, void *ptr)
|
|||
p->base = ptr;
|
||||
p->usage--;
|
||||
pool->usage--;
|
||||
pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
|
||||
if (p->usage == 0)
|
||||
// free bucket
|
||||
_eina_chained_mp_pool_free(p);
|
||||
{
|
||||
// free bucket
|
||||
pool->first = eina_inlist_remove(pool->first, EINA_INLIST_GET(p));
|
||||
_eina_chained_mp_pool_free(p);
|
||||
}
|
||||
else
|
||||
// move to front
|
||||
pool->first = eina_inlist_prepend(pool->first, EINA_INLIST_GET(p));
|
||||
{
|
||||
// move to front
|
||||
pool->first = eina_inlist_promote(pool->first, EINA_INLIST_GET(p));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,10 +132,7 @@ eina_fixed_bitmap_malloc(void *data, __UNUSED__ unsigned int size)
|
|||
ptr = (unsigned char*) (pool + 1) + index * mp->item_size;
|
||||
|
||||
if (pool->bitmask == 0)
|
||||
{
|
||||
mp->head = eina_inlist_remove(mp->head, EINA_INLIST_GET(pool));
|
||||
mp->head = eina_inlist_append(mp->head, EINA_INLIST_GET(pool));
|
||||
}
|
||||
mp->head = eina_inlist_demote(mp->head, EINA_INLIST_GET(pool));
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
@ -169,10 +166,7 @@ eina_fixed_bitmap_free(void *data, void *ptr)
|
|||
free(pool);
|
||||
}
|
||||
else if (push_front)
|
||||
{
|
||||
mp->head = eina_inlist_remove(mp->head, EINA_INLIST_GET(pool));
|
||||
mp->head = eina_inlist_prepend(mp->head, EINA_INLIST_GET(pool));
|
||||
}
|
||||
mp->head = eina_inlist_promote(mp->head, EINA_INLIST_GET(pool));
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
|
@ -99,6 +99,13 @@ START_TEST(eina_inlist_simple)
|
|||
eina_inlist_remove(NULL, EINA_INLIST_GET(tmp));
|
||||
lst = eina_inlist_remove(lst, NULL);
|
||||
|
||||
tmp = (Eina_Test_Inlist*) lst;
|
||||
lst = eina_inlist_demote(lst, lst);
|
||||
fail_if(lst == (Eina_Inlist*) tmp);
|
||||
|
||||
lst = eina_inlist_promote(lst, EINA_INLIST_GET(tmp));
|
||||
fail_if(lst != (Eina_Inlist*) tmp);
|
||||
|
||||
tmp = (Eina_Test_Inlist*) eina_inlist_find(lst, EINA_INLIST_GET(prev));
|
||||
eina_inlist_remove(lst, EINA_INLIST_GET(tmp));
|
||||
tmp = (Eina_Test_Inlist*) eina_inlist_find(lst, EINA_INLIST_GET(tmp));
|
||||
|
|
Loading…
Reference in New Issue