* eina_rectangle: Add a local cache to rectangle creation.
SVN revision: 41856
This commit is contained in:
parent
dfac5a2a59
commit
0b7407905c
|
@ -31,6 +31,7 @@
|
||||||
#include "eina_safety_checks.h"
|
#include "eina_safety_checks.h"
|
||||||
#include "eina_mempool.h"
|
#include "eina_mempool.h"
|
||||||
#include "eina_list.h"
|
#include "eina_list.h"
|
||||||
|
#include "eina_trash.h"
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Local *
|
* Local *
|
||||||
|
@ -43,6 +44,8 @@
|
||||||
#define EINA_RECTANGLE_POOL_MAGIC 0x1578FCB0
|
#define EINA_RECTANGLE_POOL_MAGIC 0x1578FCB0
|
||||||
#define EINA_RECTANGLE_ALLOC_MAGIC 0x1578FCB1
|
#define EINA_RECTANGLE_ALLOC_MAGIC 0x1578FCB1
|
||||||
|
|
||||||
|
#define BUCKET_THRESHOLD 110
|
||||||
|
|
||||||
typedef struct _Eina_Rectangle_Alloc Eina_Rectangle_Alloc;
|
typedef struct _Eina_Rectangle_Alloc Eina_Rectangle_Alloc;
|
||||||
|
|
||||||
struct _Eina_Rectangle_Pool
|
struct _Eina_Rectangle_Pool
|
||||||
|
@ -51,6 +54,9 @@ struct _Eina_Rectangle_Pool
|
||||||
Eina_List *empty;
|
Eina_List *empty;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
|
Eina_Trash *bucket;
|
||||||
|
unsigned int bucket_count;
|
||||||
|
|
||||||
unsigned int references;
|
unsigned int references;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
|
@ -82,6 +88,9 @@ static int _eina_rectangle_init_count = 0;
|
||||||
static Eina_Mempool *_eina_rectangle_alloc_mp = NULL;
|
static Eina_Mempool *_eina_rectangle_alloc_mp = NULL;
|
||||||
static Eina_Mempool *_eina_rectangle_mp = NULL;
|
static Eina_Mempool *_eina_rectangle_mp = NULL;
|
||||||
|
|
||||||
|
static Eina_Trash *_eina_rectangles = NULL;
|
||||||
|
static unsigned int _eina_rectangles_count = 0;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_eina_rectangle_cmp(const Eina_Rectangle *r1, const Eina_Rectangle *r2)
|
_eina_rectangle_cmp(const Eina_Rectangle *r1, const Eina_Rectangle *r2)
|
||||||
{
|
{
|
||||||
|
@ -285,12 +294,18 @@ eina_rectangle_init(void)
|
||||||
EAPI int
|
EAPI int
|
||||||
eina_rectangle_shutdown(void)
|
eina_rectangle_shutdown(void)
|
||||||
{
|
{
|
||||||
|
Eina_Rectangle *del;
|
||||||
|
|
||||||
--_eina_rectangle_init_count;
|
--_eina_rectangle_init_count;
|
||||||
|
|
||||||
if (_eina_rectangle_init_count) return _eina_rectangle_init_count;
|
if (_eina_rectangle_init_count) return _eina_rectangle_init_count;
|
||||||
|
|
||||||
eina_list_shutdown();
|
eina_list_shutdown();
|
||||||
|
|
||||||
|
while (del = eina_trash_pop(&_eina_rectangles))
|
||||||
|
eina_mempool_free(_eina_rectangle_mp, del);
|
||||||
|
_eina_rectangles_count = 0;
|
||||||
|
|
||||||
eina_mempool_del(_eina_rectangle_alloc_mp);
|
eina_mempool_del(_eina_rectangle_alloc_mp);
|
||||||
eina_mempool_del(_eina_rectangle_mp);
|
eina_mempool_del(_eina_rectangle_mp);
|
||||||
|
|
||||||
|
@ -305,7 +320,15 @@ eina_rectangle_new(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
Eina_Rectangle *rect;
|
Eina_Rectangle *rect;
|
||||||
|
|
||||||
rect = eina_mempool_malloc(_eina_rectangle_mp, sizeof (Eina_Rectangle));
|
if (_eina_rectangles)
|
||||||
|
{
|
||||||
|
rect = eina_trash_pop(&_eina_rectangles);
|
||||||
|
_eina_rectangles_count--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect = eina_mempool_malloc(_eina_rectangle_mp, sizeof (Eina_Rectangle));
|
||||||
|
}
|
||||||
if (!rect) return NULL;
|
if (!rect) return NULL;
|
||||||
|
|
||||||
EINA_RECTANGLE_SET(rect, x, y, w, h);
|
EINA_RECTANGLE_SET(rect, x, y, w, h);
|
||||||
|
@ -317,7 +340,16 @@ EAPI void
|
||||||
eina_rectangle_free(Eina_Rectangle *rect)
|
eina_rectangle_free(Eina_Rectangle *rect)
|
||||||
{
|
{
|
||||||
EINA_SAFETY_ON_NULL_RETURN(rect);
|
EINA_SAFETY_ON_NULL_RETURN(rect);
|
||||||
eina_mempool_free(_eina_rectangle_mp, rect);
|
|
||||||
|
if (_eina_rectangles_count > BUCKET_THRESHOLD)
|
||||||
|
{
|
||||||
|
eina_mempool_free(_eina_rectangle_mp, rect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eina_trash_push(&_eina_rectangles, rect);
|
||||||
|
_eina_rectangles_count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Eina_Rectangle_Pool *
|
EAPI Eina_Rectangle_Pool *
|
||||||
|
@ -334,6 +366,8 @@ eina_rectangle_pool_new(int w, int h)
|
||||||
new->sorted = EINA_FALSE;
|
new->sorted = EINA_FALSE;
|
||||||
new->w = w;
|
new->w = w;
|
||||||
new->h = h;
|
new->h = h;
|
||||||
|
new->bucket = NULL;
|
||||||
|
new->bucket_count = 0;
|
||||||
|
|
||||||
EINA_MAGIC_SET(new, EINA_RECTANGLE_POOL_MAGIC);
|
EINA_MAGIC_SET(new, EINA_RECTANGLE_POOL_MAGIC);
|
||||||
|
|
||||||
|
@ -356,6 +390,12 @@ eina_rectangle_pool_free(Eina_Rectangle_Pool *pool)
|
||||||
eina_mempool_free(_eina_rectangle_alloc_mp, del);
|
eina_mempool_free(_eina_rectangle_alloc_mp, del);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (pool->bucket)
|
||||||
|
{
|
||||||
|
del = eina_trash_pop(&pool->bucket);
|
||||||
|
eina_mempool_free(_eina_rectangle_alloc_mp, del);
|
||||||
|
}
|
||||||
|
|
||||||
MAGIC_FREE(pool);
|
MAGIC_FREE(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +430,16 @@ eina_rectangle_pool_request(Eina_Rectangle_Pool *pool, int w, int h)
|
||||||
if (x == -1) return NULL;
|
if (x == -1) return NULL;
|
||||||
pool->sorted = EINA_FALSE;
|
pool->sorted = EINA_FALSE;
|
||||||
|
|
||||||
new = eina_mempool_malloc(_eina_rectangle_alloc_mp,
|
if (pool->bucket_count > 0)
|
||||||
sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle));
|
{
|
||||||
|
new = eina_trash_pop(&pool->bucket);
|
||||||
|
pool->bucket_count--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new = eina_mempool_malloc(_eina_rectangle_alloc_mp,
|
||||||
|
sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle));
|
||||||
|
}
|
||||||
if (!new) return NULL;
|
if (!new) return NULL;
|
||||||
|
|
||||||
rect = (Eina_Rectangle*) (new + 1);
|
rect = (Eina_Rectangle*) (new + 1);
|
||||||
|
@ -428,8 +476,20 @@ eina_rectangle_pool_release(Eina_Rectangle *rect)
|
||||||
era->pool->sorted = EINA_FALSE;
|
era->pool->sorted = EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
EINA_MAGIC_SET(era, EINA_MAGIC_NONE);
|
if (era->pool->bucket_count < BUCKET_THRESHOLD)
|
||||||
eina_mempool_free(_eina_rectangle_alloc_mp, era);
|
{
|
||||||
|
Eina_Rectangle_Pool *pool;
|
||||||
|
|
||||||
|
pool = era->pool;
|
||||||
|
|
||||||
|
pool->bucket_count++;
|
||||||
|
eina_trash_push(&pool->bucket, era);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EINA_MAGIC_SET(era, EINA_MAGIC_NONE);
|
||||||
|
eina_mempool_free(_eina_rectangle_alloc_mp, era);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Eina_Rectangle_Pool *
|
EAPI Eina_Rectangle_Pool *
|
||||||
|
|
Loading…
Reference in New Issue