Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/evas

Dir     : e17/libs/evas/src/lib/data


Modified Files:
        Makefile.am evas_hash.c 
Added Files:
        evas_stringshare.c 


Log Message:


use stringshare. saves a few hundred allocs... if we start doing lots of text
:)

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/data/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- Makefile.am 3 Sep 2005 19:42:28 -0000       1.8
+++ Makefile.am 28 Nov 2005 15:18:00 -0000      1.9
@@ -14,6 +14,7 @@
 libevas_data_la_SOURCES  = \
 evas_hash.c \
 evas_list.c \
-evas_object_list.c
+evas_object_list.c \
+evas_stringshare.c
 
 libevas_data_la_DEPENDENCIES = $(top_builddir)/config.h
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/data/evas_hash.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- evas_hash.c 3 Nov 2005 12:13:09 -0000       1.15
+++ evas_hash.c 28 Nov 2005 15:18:00 -0000      1.16
@@ -117,7 +117,70 @@
    if (evas_list_alloc_error())
      {
        _evas_hash_alloc_error = 1;
-       if (el->key) free(el->key);
+       free(el);
+       return hash;
+     }
+   hash->population++;
+   return hash;
+}
+
+/**
+ * Adds an entry to the given hash table and does not duplicate the string key.
+ *
+ * @p key is expected to be a unique string within the hash table.
+ * Otherwise, you cannot be sure which inserted data pointer will be
+ * accessed with @ref evas_hash_find , and removed with
+ * @ref evas_hash_del . This call does nto make a copy of the key so it must
+ * be a string constant or stored elsewhere (in the object being added) etc.
+ *
+ * Key strings are case sensitive.
+ *
+ * @ref evas_hash_alloc_error should be used to determine if an
+ * allocation error occurred during this function.
+ *
+ * @param   hash The given hash table.  Can be @c NULL, in which case a
+ *               new hash table is allocated and returned.
+ * @param   key  A unique string.  Can be @c NULL.
+ * @param   data Data to associate with the string given by @p key.
+ * @return  Either the given hash table, or if the given value for @p
+ *          hash is @c NULL, then a new one.  @c NULL will be returned
+ *          if memory could not be allocated for a new table.
+ * @ingroup Evas_Hash_Data
+ */
+Evas_Hash *
+evas_hash_direct_add(Evas_Hash *hash, const char *key, const void *data)
+{
+   int hash_num;
+   Evas_Hash_El *el;
+
+   if ((!key) || (!data)) return hash;
+   _evas_hash_alloc_error = 0;
+   if (!hash)
+     {
+       hash = calloc(1, sizeof(struct _Evas_Hash));
+       if (!hash)
+         {
+            _evas_hash_alloc_error = 1;
+            return NULL;
+         }
+     }
+   if (!(el = malloc(sizeof(struct _Evas_Hash_El))))
+     {
+        if (hash->population <= 0)
+         {
+            free(hash);
+            hash = NULL;
+         }
+       _evas_hash_alloc_error = 1;
+       return hash;
+     };
+   el->key = key;
+   el->data = (void *)data;
+   hash_num = _evas_hash_gen(key);
+   hash->buckets[hash_num] = evas_object_list_prepend(hash->buckets[hash_num], 
el);
+   if (evas_list_alloc_error())
+     {
+       _evas_hash_alloc_error = 1;
        free(el);
        return hash;
      }




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to