Why don't u and others just create hashes at begining? They're not expensive

On 12/17/08, Enlightenment SVN <no-re...@enlightenment.org> wrote:
> Log:
>   Move to eina_hash. Nothing should break, but if you experience any
> unexpected behaviour
>   please ping me on #edevelop.
>
>
> Author:       cedric
> Date:         2008-12-17 06:26:47 -0800 (Wed, 17 Dec 2008)
> New Revision: 38183
>
> Modified:
>   trunk/edje/src/bin/edje_cc_sources.c trunk/edje/src/lib/edje_cache.c
> trunk/edje/src/lib/edje_calc.c trunk/edje/src/lib/edje_data.c
> trunk/edje/src/lib/edje_edit.c trunk/edje/src/lib/edje_load.c
> trunk/edje/src/lib/edje_private.h trunk/edje/src/lib/edje_program.c
> trunk/edje/src/lib/edje_text.c trunk/edje/src/lib/edje_util.c
>
> Modified: trunk/edje/src/bin/edje_cc_sources.c
> ===================================================================
> --- trunk/edje/src/bin/edje_cc_sources.c      2008-12-17 14:10:09 UTC (rev 
> 38182)
> +++ trunk/edje/src/bin/edje_cc_sources.c      2008-12-17 14:26:47 UTC (rev 
> 38183)
> @@ -30,6 +30,19 @@
>  {
>  }
>
> +static void *
> +_edje_eina_hash_add_alloc(void *hash, const char *key, void *data)
> +{
> +   Eina_Hash *result = hash;
> +
> +   if (!result) result = eina_hash_string_small_new(NULL);
> +   if (!result) return NULL;
> +
> +   eina_hash_add(result, key, data);
> +
> +   return result;
> +}
> +
>  void
>  source_edd(void)
>  {
> @@ -38,15 +51,15 @@
>     eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
>     eddc.func.mem_alloc = NULL;
>     eddc.func.mem_free = NULL;
> -   eddc.func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
> -   eddc.func.str_free = (void (*)(const char *))eina_stringshare_del;
> -   eddc.func.list_next = (void *(*)(void *))eina_list_next;
> -   eddc.func.list_append = (void *(*)(void *, void *))eina_list_append;
> -   eddc.func.list_data = (void *(*)(void *))eina_list_data_get;
> -   eddc.func.list_free = (void *(*)(void *))eina_list_free;
> -   eddc.func.hash_foreach = (void (*)(void *, int (*) (void *, const char
> *, void *, void *), void *))evas_hash_foreach;
> -   eddc.func.hash_add = (void *(*)(void *, const char *, void
> *))evas_hash_add;
> -   eddc.func.hash_free = (void (*)(void *))evas_hash_free;
> +   eddc.func.str_alloc = eina_stringshare_add;
> +   eddc.func.str_free = eina_stringshare_del;
> +   eddc.func.list_next = eina_list_next;
> +   eddc.func.list_append = eina_list_append;
> +   eddc.func.list_data = eina_list_data_get;
> +   eddc.func.list_free = eina_list_free;
> +   eddc.func.hash_foreach = eina_hash_foreach;
> +   eddc.func.hash_add = _edje_eina_hash_add_alloc;
> +   eddc.func.hash_free = eina_hash_free;
>     eddc.func.str_direct_alloc = _edje_str_direct_alloc;
>     eddc.func.str_direct_free = _edje_str_direct_free;
>
>
> Modified: trunk/edje/src/lib/edje_cache.c
> ===================================================================
> --- trunk/edje/src/lib/edje_cache.c   2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_cache.c   2008-12-17 14:26:47 UTC (rev 38183)
> @@ -28,7 +28,7 @@
>
>  #include "edje_private.h"
>
> -static Eina_Hash   *_edje_file_hash = NULL;
> +static Evas_Hash   *_edje_file_hash = NULL;
>  static int          _edje_file_cache_size = 16;
>  static Eina_List   *_edje_file_cache = NULL;
>
> @@ -69,7 +69,9 @@
>
>     edc->part = eina_stringshare_add(coll);
>     edc->references = 1;
> -   edf->collection_hash = evas_hash_add(edf->collection_hash, coll, edc);
> +   if (!edf->collection_hash)
> +     edf->collection_hash = eina_hash_string_superfast_new(NULL);
> +   eina_hash_add(edf->collection_hash, coll, edc);
>     return edc;
>  }
>
> @@ -78,6 +80,9 @@
>  {
>     int       count = 0;
>
> +   if (!edf->font_hash)
> +     edf->font_hash = eina_hash_string_superfast_new(NULL);
> +
>     if (edf->font_dir)
>       {
>       Eina_List *l;
> @@ -96,7 +101,7 @@
>               if (edf->free_strings)
>                 eina_stringshare_del(fnt->entry);
>            fnt->entry = fnt->path + 6;
> -          edf->font_hash = evas_hash_direct_add(edf->font_hash, fnt->entry,
> fnt);
> +          eina_hash_direct_add(edf->font_hash, fnt->entry, fnt);
>
>            count++;
>         }
> @@ -156,8 +161,10 @@
>
>     _edje_textblock_style_parse_and_fix(edf);
>
> +   if (!edf->data_cache)
> +     edf->data_cache = eina_hash_string_superfast_new(NULL);
>     EINA_LIST_FOREACH(edf->data, l, di)
> -     edf->data_cache = evas_hash_add(edf->data_cache,
> eina_stringshare_add(di->key), di->value);
> +     eina_hash_add(edf->data_cache, di->key, di->value);
>
>     if (coll)
>       {
> @@ -184,10 +191,15 @@
>     Edje_Part_Collection *edc;
>     Edje_Part *ep;
>
> -   edf = evas_hash_find(_edje_file_hash, file);
> +   if (!_edje_file_hash)
> +     _edje_file_hash = eina_hash_string_superfast_new(NULL);
> +   edf = eina_hash_find(_edje_file_hash, file);
> +
>     if (edf)
>       {
>       edf->references++;
> +     if (!edf->collection_hash)
> +       edf->collection_hash = eina_hash_string_superfast_new(NULL);
>       }
>     else
>       {
> @@ -197,7 +209,7 @@
>              {
>                 edf->references = 1;
>                 _edje_file_cache = eina_list_remove_list(_edje_file_cache, l);
> -               _edje_file_hash = evas_hash_add(_edje_file_hash, file, edf);
> +               eina_hash_add(_edje_file_hash, file, edf);
>                 break;
>              }
>            edf = NULL;
> @@ -207,13 +219,13 @@
>       {
>       edf = _edje_file_open(file, coll, error_ret, edc_ret);
>       if (!edf) return NULL;
> -     _edje_file_hash = evas_hash_add(_edje_file_hash, file, edf);
> +     eina_hash_add(_edje_file_hash, file, edf);
>       return edf;
>       }
>
>     if (!coll) return edf;
>
> -   edc = evas_hash_find(edf->collection_hash, coll);
> +   edc = eina_hash_find(edf->collection_hash, coll);
>     if (edc)
>       {
>       edc->references++;
> @@ -226,7 +238,7 @@
>              {
>                 edc->references = 1;
>                 edf->collection_cache = 
> eina_list_remove_list(edf->collection_cache,
> l);
> -               edf->collection_hash = evas_hash_add(edf->collection_hash, 
> coll, edc);
> +               eina_hash_add(edf->collection_hash, coll, edc);
>                 break;
>              }
>            edc = NULL;
> @@ -345,7 +357,12 @@
>  {
>     edc->references--;
>     if (edc->references != 0) return;
> -   edf->collection_hash = evas_hash_del(edf->collection_hash, edc->part,
> edc);
> +   eina_hash_del(edf->collection_hash, edc->part, edc);
> +   if (!eina_hash_population(edf->collection_hash))
> +     {
> +       eina_hash_free(edf->collection_hash);
> +       edf->collection_hash = NULL;
> +     }
>     edf->collection_cache = eina_list_prepend(edf->collection_cache, edc);
>     _edje_cache_coll_clean(edf);
>  }
> @@ -372,7 +389,13 @@
>  {
>     edf->references--;
>     if (edf->references != 0) return;
> -   _edje_file_hash = evas_hash_del(_edje_file_hash, edf->path, edf);
> +
> +   eina_hash_del(_edje_file_hash, edf->path, edf);
> +   if (!eina_hash_population(_edje_file_hash))
> +     {
> +       eina_hash_free(_edje_file_hash);
> +       _edje_file_hash = NULL;
> +     }
>     _edje_file_cache = eina_list_prepend(_edje_file_cache, edf);
>     _edje_cache_file_clean();
>  }
>
> Modified: trunk/edje/src/lib/edje_calc.c
> ===================================================================
> --- trunk/edje/src/lib/edje_calc.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_calc.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -777,7 +777,7 @@
>         {
>            Edje_Font_Directory_Entry *fnt;
>
> -          fnt = evas_hash_find(ed->file->font_hash, font);
> +          fnt = eina_hash_find(ed->file->font_hash, font);
>
>            if (fnt)
>              {
>
> Modified: trunk/edje/src/lib/edje_data.c
> ===================================================================
> --- trunk/edje/src/lib/edje_data.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_data.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -75,6 +75,16 @@
>  {
>  }
>
> +static Eina_Hash *
> +_edje_eina_hash_add_alloc(Eina_Hash *hash, const char *key, void *data)
> +{
> +   if (!hash) hash = eina_hash_string_small_new(NULL);
> +   if (!hash) return NULL;
> +
> +   eina_hash_add(hash, key, data);
> +   return hash;
> +}
> +
>  void
>  _edje_edd_setup(void)
>  {
> @@ -89,9 +99,9 @@
>     eddc.func.list_append = (void *(*)(void *, void *))eina_list_append;
>     eddc.func.list_data = (void *(*)(void *))eina_list_data_get;
>     eddc.func.list_free = (void *(*)(void *))eina_list_free;
> -   eddc.func.hash_foreach = (void (*)(void *, int (*)(void *, const char *,
> void *, void *), void *))evas_hash_foreach;
> -   eddc.func.hash_add = (void *(*)(void *, const char *, void
> *))evas_hash_add;
> -   eddc.func.hash_free = (void (*)(void *))evas_hash_free;
> +   eddc.func.hash_foreach = (void (*)(const Eina_Hash *, Eina_Bool
> (*)(const Eina_Hash *, const void *, void *, void *), void
> *))eina_hash_foreach;
> +   eddc.func.hash_add = (Eina_Hash* (*)(Eina_Hash *, const char *, void *))
> _edje_eina_hash_add_alloc;
> +   eddc.func.hash_free = (void (*)(void *))eina_hash_free;
>     eddc.func.str_direct_alloc = _edje_str_direct_alloc;
>     eddc.func.str_direct_free = _edje_str_direct_free;
>
>
> Modified: trunk/edje/src/lib/edje_edit.c
> ===================================================================
> --- trunk/edje/src/lib/edje_edit.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_edit.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -716,7 +716,9 @@
>     //cd = mem_alloc(SZ(Code));
>     //codes = eina_list_append(codes, cd);
>
> -   ed->file->collection_hash = evas_hash_add(ed->file->collection_hash,
> name, pc);
> +   if (!ed->file->collection_hash)
> +     ed->file->collection_hash = eina_hash_string_superfast_new(NULL);
> +   eina_hash_add(ed->file->collection_hash, name, pc);
>
>     return 1;
>  }
> @@ -828,10 +830,12 @@
>       {
>       if (pc->id == pce->id)
>         {
> -          ed->file->collection_hash = 
> evas_hash_del(ed->file->collection_hash,
> -                                                    pce->entry, NULL);
> -          ed->file->collection_hash = 
> evas_hash_add(ed->file->collection_hash,
> -                                                    new_name, pc);
> +          eina_hash_del(ed->file->collection_hash,
> +                        pce->entry, NULL);
> +          if (!ed->file->collection_hash)
> +            ed->file->collection_hash = eina_hash_string_superfast_new(NULL);
> +          eina_hash_add(ed->file->collection_hash,
> +                        new_name, pc);
>
>            //if (pce->entry &&  //TODO Also this cause segv
>            //    
> !eet_dictionary_string_check(eet_dictionary_get(ed->file->ef),
> pce->entry))
> @@ -1295,7 +1299,7 @@
>  edje_edit_style_tags_list_get(Evas_Object * obj, const char* style)
>  {
>     Eina_List *tags = NULL;
> -   Eina_List *ll;
> +   Eina_List *l, *ll;
>     Edje_Style *s;
>     Edje_Style_Tag *t;
>
> @@ -3310,7 +3314,9 @@
>       fnt->path = mem_strdup(buf);
>
>       ed->file->font_dir->entries =
> eina_list_append(ed->file->font_dir->entries, fnt);
> -     ed->file->font_hash = evas_hash_direct_add(ed->file->font_hash,
> fnt->entry, fnt);
> +     if (!ed->file->font_hash)
> +       ed->file->font_hash = eina_hash_string_superfast_new(NULL);
> +     eina_hash_direct_add(ed->file->font_hash, fnt->entry, fnt);
>       }
>
>     return 1;
> @@ -5397,6 +5403,20 @@
>  {
>  }
>
> +static void *
> +_edje_eina_hash_add_alloc(void *hash, const void *key, void *data)
> +{
> +   Eina_Hash *result = hash;
> +
> +   if (!result) result = eina_hash_string_small_new(NULL);
> +   if (!result) return NULL;
> +
> +   eina_hash_add(result, key, data);
> +
> +   return result;
> +}
> +
> +
>  static Eet_Data_Descriptor *_srcfile_edd = NULL;
>  static Eet_Data_Descriptor *_srcfile_list_edd = NULL;
>
> @@ -5408,15 +5428,15 @@
>     eddc.version = EET_DATA_DESCRIPTOR_CLASS_VERSION;
>     eddc.func.mem_alloc = NULL;
>     eddc.func.mem_free = NULL;
> -   eddc.func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
> -   eddc.func.str_free = (void (*)(const char *))eina_stringshare_del;
> -   eddc.func.list_next = (void *(*)(void *))eina_list_next;
> -   eddc.func.list_append = (void *(*)(void *, void *))eina_list_append;
> -   eddc.func.list_data = (void *(*)(void *))eina_list_data_get;
> -   eddc.func.list_free = (void *(*)(void *))eina_list_free;
> -   eddc.func.hash_foreach = (void (*)(void *, int (*) (void *, const char
> *, void *, void *), void *))evas_hash_foreach;
> -   eddc.func.hash_add = (void *(*)(void *, const char *, void
> *))evas_hash_add;
> -   eddc.func.hash_free = (void (*)(void *))evas_hash_free;
> +   eddc.func.str_alloc = eina_stringshare_add;
> +   eddc.func.str_free = eina_stringshare_del;
> +   eddc.func.list_next = eina_list_next;
> +   eddc.func.list_append = eina_list_append;
> +   eddc.func.list_data = eina_list_data_get;
> +   eddc.func.list_free = eina_list_free;
> +   eddc.func.hash_foreach = eina_hash_foreach;
> +   eddc.func.hash_add = _edje_eina_hash_add_alloc;
> +   eddc.func.hash_free = eina_hash_free;
>     eddc.func.str_direct_alloc = _edje_edit_str_direct_alloc;
>     eddc.func.str_direct_free = _edje_edit_str_direct_free;
>
>
> Modified: trunk/edje/src/lib/edje_load.c
> ===================================================================
> --- trunk/edje/src/lib/edje_load.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_load.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -855,6 +855,11 @@
>         }
>       free(edf->font_dir);
>       }
> +   if (edf->font_hash)
> +     {
> +     eina_hash_free(edf->font_hash);
> +     edf->font_hash = NULL;
> +     }
>     if (edf->image_dir)
>       {
>       while (edf->image_dir->entries)
>
> Modified: trunk/edje/src/lib/edje_private.h
> ===================================================================
> --- trunk/edje/src/lib/edje_private.h 2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_private.h 2008-12-17 14:26:47 UTC (rev 38183)
> @@ -255,10 +255,10 @@
>     int                             version;
>     int                             feature_ver;
>
> -   Evas_Hash                      *collection_hash;
> -   Evas_Hash                   *font_hash;
> +   Eina_Hash                      *collection_hash;
> +   Eina_Hash                   *font_hash;
>     Eina_List                      *collection_cache;
> -   Evas_Hash                      *data_cache;
> +   Eina_Hash                      *data_cache;
>
>     Eet_File                       *ef;
>
> @@ -433,8 +433,8 @@
>     int        references;
>  #ifdef EDJE_PROGRAM_CACHE
>     struct {
> -      Evas_Hash                   *no_matches;
> -      Evas_Hash                   *matches;
> +      Eina_Hash                   *no_matches;
> +      Eina_Hash                   *matches;
>     } prog_cache;
>  #endif
>
> @@ -880,7 +880,7 @@
>
>  struct _Edje_Var_Hash
>  {
> -   Evas_Hash *v;
> +   Eina_Hash *v;
>  };
>
>  struct _Edje_Var_Timer
>
> Modified: trunk/edje/src/lib/edje_program.c
> ===================================================================
> --- trunk/edje/src/lib/edje_program.c 2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_program.c 2008-12-17 14:26:47 UTC (rev 38183)
> @@ -933,11 +933,11 @@
>            Eina_List *l;
>            Edje_Program *pr;
>
> -          if (evas_hash_find(ec->prog_cache.no_matches, tmps))
> +          if (eina_hash_find(ec->prog_cache.no_matches, tmps))
>              {
>                 done = 1;
>              }
> -          else if ((matches = evas_hash_find(ec->prog_cache.matches, tmps)))
> +          else if ((matches = eina_hash_find(ec->prog_cache.matches, tmps)))
>              {
>                EINA_LIST_FOREACH(matches, l, pr)
>                   {
> @@ -988,11 +988,17 @@
>            if (tmps)
>              {
>                 if (data.matched == 0)
> -                 ec->prog_cache.no_matches =
> -                 evas_hash_add(ec->prog_cache.no_matches, tmps, ed);
> +                 {
> +                   if (!ec->prog_cache.no_matches)
> +                     ec->prog_cache.no_matches = 
> eina_hash_string_superfast_new(NULL);
> +                   eina_hash_add(ec->prog_cache.no_matches, tmps, ed);
> +                 }
>                 else
> -                 ec->prog_cache.matches =
> -                 evas_hash_add(ec->prog_cache.matches, tmps, data.matches);
> +                 {
> +                   if (!ec->prog_cache.matches)
> +                     ec->prog_cache.matches = 
> eina_hash_string_superfast_new(NULL);
> +                   eina_hash_add(ec->prog_cache.matches, tmps, data.matches);
> +                 }
>              }
>  #endif
>         }
>
> Modified: trunk/edje/src/lib/edje_text.c
> ===================================================================
> --- trunk/edje/src/lib/edje_text.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_text.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -359,7 +359,7 @@
>     /* check if the font is embedded in the .eet */
>     if (ed->file->font_hash)
>       {
> -     Edje_Font_Directory_Entry *fnt = evas_hash_find(ed->file->font_hash,
> font);
> +     Edje_Font_Directory_Entry *fnt = eina_hash_find(ed->file->font_hash,
> font);
>
>       if (fnt)
>         {
>
> Modified: trunk/edje/src/lib/edje_util.c
> ===================================================================
> --- trunk/edje/src/lib/edje_util.c    2008-12-17 14:10:09 UTC (rev 38182)
> +++ trunk/edje/src/lib/edje_util.c    2008-12-17 14:26:47 UTC (rev 38183)
> @@ -20,11 +20,11 @@
>  typedef struct _Edje_Box_Layout                      Edje_Box_Layout;
>
>
> -static Eina_Hash *_edje_color_class_hash = NULL;
> -static Eina_Hash *_edje_color_class_member_hash = NULL;
> +static Evas_Hash *_edje_color_class_hash = NULL;
> +static Evas_Hash *_edje_color_class_member_hash = NULL;
>
> -static Eina_Hash *_edje_text_class_hash = NULL;
> -static Eina_Hash *_edje_text_class_member_hash = NULL;
> +static Evas_Hash *_edje_text_class_hash = NULL;
> +static Evas_Hash *_edje_text_class_member_hash = NULL;
>
>  static Eina_Rbtree *_edje_box_layout_registry = NULL;
>
> @@ -40,8 +40,8 @@
>     Eina_List *list;
>  };
>
> -static Eina_Bool _edje_color_class_list_foreach(const Eina_Hash *hash,
> const void *key, void *data, void *fdata);
> -static Eina_Bool _edje_text_class_list_foreach(const Eina_Hash *hash, const
> void *key, void *data, void *fdata);
> +static Evas_Bool _edje_color_class_list_foreach(const Eina_Hash *hash,
> const void *key, void *data, void *fdata);
> +static Evas_Bool _edje_text_class_list_foreach(const Eina_Hash *hash, const
> void *key, void *data, void *fdata);
>
>  Edje_Real_Part *_edje_real_part_recursive_get_helper(Edje *ed, char
> **path);
>
>
>
> ------------------------------------------------------------------------------
> SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
> The future of the web can't happen without you.  Join us at MIX09 to help
> pave the way to the Next Web now. Learn more and register at
> http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
> _______________________________________________
> enlightenment-svn mailing list
> enlightenment-...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
>

-- 
Sent from my mobile device

Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: barbi...@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to