On Mon, Apr 14, 2008 at 7:51 PM, Gustavo Sverzut Barbieri
<[EMAIL PROTECTED]> wrote:
> On Mon, Apr 14, 2008 at 12:38 PM, Cedric BAIL <[EMAIL PROTECTED]> wrote:
>  > On Mon, Apr 14, 2008 at 11:55 AM, Cedric BAIL <[EMAIL PROTECTED]> wrote:
>  >  > On Sun, Apr 13, 2008 at 9:52 PM, Gustavo Sverzut Barbieri
>  >  >  <[EMAIL PROTECTED]> wrote:
>  >  >  > On Sun, Apr 13, 2008 at 1:33 PM, Cedric BAIL <[EMAIL PROTECTED]> 
> wrote:
>  >  >  >  > On Fri, Apr 11, 2008 at 8:56 PM, Cedric BAIL <[EMAIL PROTECTED]> 
> wrote:
>  > >  >    - evas_array seems very useful, make it available to evas as a
>  >  >  >  whole! Just have it to take "void *" and it will do just fine. Also,
>  >  >  >  I'd make the increase amount (16) configurable after the array is
>  >  >  >  created (or provide an alternative constructor).
>  >  >
>  >  >  Good idea, but as this are small functions and some are used a lot I
>  >  >  like the idea of seeing them inlined. As there are more of this kind
>  >  >  of function in Evas, small functions used a lot, I did move them after
>  >  >  some profiling inside src/lib/include/evas_inline.x. This give us a
>  >  >  little bit of speedup with only a small increase in library size. The
>  >  >  function that could be inlined are :
>  >  >  - evas_object_is_opaque
>  >  >  - evas_event_passes_through
>  >  >  - evas_object_is_visible
>  >  >  - evas_object_clippers_is_visible
>  >  >  - evas_object_is_in_output_rect
>  >  >  - evas_object_is_active
>  >  >  - evas_object_coords_recalc
>  >  >  - evas_object_clip_recalc
>  >  >
>  >  >  Are people interested by this kind of patch ? I would add
>  >  >  evas_object_array_push to this list also.
>  >
>  >  Because code is better than discussion, here is a patch that does
>  >  exactly that. Comment are welcome :-)

>  I like it. It could be dangerous for externally used calls, but for
>  those exported in evas_private.h, it makes sense.

Right now, none of this function are exported to the outside.

>  I just think that some functions should be split in 2 parts: common
>  and corner, just the common part should be inline, while the corner,
>  usually bigger, should be regular function defined in evas_private.h.
>  This would avoid code growing too much while giving us the fast common
>  path. For example: evas_array_push will not have to realloc most of
>  times, so it should be in another function:

I like this idea. So next patch with it :-)

>  Also, for _internal_ things I really dislike null-pointer checking: we
>  should never have one, if we do then we are buggy and must crash ASAP
>  to catch the error sooner. Just entry-point should do these checks to
>  make library robust.

I like the idea of checking NULL pointer often, perhaps it will be
better if I do it with assert so we can easily remove this test.

So here is a implementation of Evas_Array on top of previous inline patch.
-- 
Cedric BAIL
From 9766085ed47d93b5e7402d1bf60d616c7a4c625e Mon Sep 17 00:00:00 2001
From: Cedric BAIL <[EMAIL PROTECTED]>
Date: Tue, 15 Apr 2008 10:48:15 +0200
Subject: [PATCH] Implement new Evas_Array support.

---
 src/lib/Evas.h                 |   17 +++++++++
 src/lib/data/Makefile.am       |    1 +
 src/lib/data/evas_array.c      |   75 ++++++++++++++++++++++++++++++++++++++++
 src/lib/include/evas_inline.x  |   15 ++++++++
 src/lib/include/evas_private.h |   10 +----
 5 files changed, 110 insertions(+), 8 deletions(-)
 create mode 100644 src/lib/data/evas_array.c

diff --git a/src/lib/Evas.h b/src/lib/Evas.h
index 3d9b1a4..a83448a 100644
--- a/src/lib/Evas.h
+++ b/src/lib/Evas.h
@@ -84,6 +84,7 @@ typedef enum _Evas_Colorspace
    EVAS_COLORSPACE_RGB565_A5P /**< 16bit rgb565 + Alpha plane at end - 5 bits of the 8 being used per alpha byte */
 } Evas_Colorspace; /**< Colorspaces for pixel data supported by Evas */
 
+typedef struct _Evas_Array            Evas_Array; /**< A generic vector */
 typedef struct _Evas_List             Evas_List; /**< A generic linked list node handle */
 typedef struct _Evas_Rectangle        Evas_Rectangle; /**< A generic rectangle handle */
 typedef struct _Evas_Smart_Class      Evas_Smart_Class; /**< A smart object base class */
@@ -103,6 +104,14 @@ typedef int    Evas_Font_Size;
 typedef int    Evas_Angle;
 typedef char   Evas_Bool;
 
+struct _Evas_Array /** An array of data */
+{
+   void		**data; /**< Pointer to a vector of pointer to payload */
+   unsigned int   total; /**< Total number of slot in the vector */
+   unsigned int   count; /**< Number of activ slot in the vector */
+   unsigned int	  step; /**< How much must we grow the vector When it is full */
+};
+
 struct _Evas_List /** A linked list node */
 {
    void      *data; /**< Pointer to list element payload */
@@ -395,6 +404,14 @@ extern "C" {
    EAPI Evas_List        *evas_list_sort                    (Evas_List *list, int size, int(*func)(void*,void*));
    EAPI int               evas_list_alloc_error             (void);
 
+   EAPI Evas_Array	 *evas_array_new		    (unsigned int step);
+   EAPI void		  evas_array_setup		    (Evas_Array *array, unsigned int step);
+   EAPI void		  evas_array_free		    (Evas_Array *array);
+   EAPI void		  evas_array_append		    (Evas_Array *array, void *data);
+   EAPI void		 *evas_array_get		    (Evas_Array *array, unsigned int index);
+   EAPI void		  evas_array_clean		    (Evas_Array *array);
+   EAPI void		  evas_array_flush		    (Evas_Array *array);
+
    /* FIXME: add:
     * api to add find, del members by data, size not just string and also
     * provide hash generation functions settable by the app
diff --git a/src/lib/data/Makefile.am b/src/lib/data/Makefile.am
index dfb8470..0d4bcec 100644
--- a/src/lib/data/Makefile.am
+++ b/src/lib/data/Makefile.am
@@ -13,6 +13,7 @@ noinst_LTLIBRARIES      = libevas_data.la
 libevas_data_la_SOURCES  = \
 evas_hash.c \
 evas_list.c \
+evas_array.c \
 evas_object_list.c \
 evas_stringshare.c
 
diff --git a/src/lib/data/evas_array.c b/src/lib/data/evas_array.c
new file mode 100644
index 0000000..764750c
--- /dev/null
+++ b/src/lib/data/evas_array.c
@@ -0,0 +1,75 @@
+#include "evas_common.h"
+#include "evas_private.h"
+
+Evas_Bool
+_evas_array_grow(Evas_Array *array)
+{
+   void **tmp;
+   unsigned int total;
+
+   total = array->total + 16;
+   tmp = realloc(array->data, sizeof (void*) * total);
+   if (!tmp) return 0;
+
+   array->total = total;
+   array->data = tmp;
+
+   return 1;
+}
+
+EAPI void
+evas_array_append(Evas_Array *array, void *data)
+{
+   _evas_array_append(array, data);
+}
+
+EAPI void*
+evas_array_get(Evas_Array *array, unsigned int index)
+{
+   return _evas_array_get(array, index);
+}
+
+EAPI void
+evas_array_clean(Evas_Array *array)
+{
+   array->count = 0;
+}
+
+EAPI void
+evas_array_setup(Evas_Array *array, unsigned int step)
+{
+   array->step = step;
+}
+
+EAPI void
+evas_array_flush(Evas_Array *array)
+{
+   array->count = 0;
+   array->total = 0;
+
+   if (array->data) free(array->data);
+   array->data = NULL;
+}
+
+EAPI Evas_Array*
+evas_array_new(unsigned int step)
+{
+   Evas_Array *array;
+
+   array = malloc(sizeof (Evas_Array));
+   if (!array) return NULL;
+
+   array->data = NULL;
+   array->total = 0;
+   array->count = 0;
+   array->step = step;
+
+   return array;
+}
+
+EAPI void
+evas_array_free(Evas_Array *array)
+{
+   evas_array_flush(array);
+   free(array);
+}
diff --git a/src/lib/include/evas_inline.x b/src/lib/include/evas_inline.x
index 2489c94..1f2e24d 100644
--- a/src/lib/include/evas_inline.x
+++ b/src/lib/include/evas_inline.x
@@ -158,4 +158,19 @@ evas_object_clip_recalc(Evas_Object *obj)
    obj->cur.cache.clip.dirty = 0;
 }
 
+static inline void
+_evas_array_append(Evas_Array *array, void *data)
+{
+   if (UNLIKELY(array->count + array->step > array->total))
+     if (!_evas_array_grow(array)) return ;
+
+   array->data[array->count++] = data;
+}
+
+static inline void*
+_evas_array_get(Evas_Array *array, unsigned int index)
+{
+   return array->data[index];
+}
+
 #endif
diff --git a/src/lib/include/evas_private.h b/src/lib/include/evas_private.h
index 64fb3fd..921a0ab 100644
--- a/src/lib/include/evas_private.h
+++ b/src/lib/include/evas_private.h
@@ -847,6 +839,8 @@ EAPI int _evas_module_engine_inherit(Evas_Func *funcs, char *name);
 void evas_render_invalidate(Evas *e);
 void evas_render_object_recalc(Evas_Object *obj);
 
+Evas_Bool _evas_array_grow(Evas_Array *array);
+
 #define EVAS_API_OVERRIDE(func, api, prefix) \
      (api)->func = prefix##func
 
-- 
1.5.4.GIT

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to