[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: branch: master updated (1.1.2.20070818-128-g53cbd81)



The branch, master has been updated
       via  53cbd813e6d601f86618aa083d656d7aeccb7705 (commit)
      from  9d2d7b0042a75f0494a240ceb79e60173d2e55d7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 libgeda/src/s_clib.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)


=================
 Commit Messages
=================

commit 53cbd813e6d601f86618aa083d656d7aeccb7705
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date:   Tue Dec 4 22:56:01 2007 +0000

    clib: Speed up caching by using pointer rather than string keys.
    
    The initial version of the symbol cache used the symbol name as a
    string as the key, mostly because of the obnoxious 'const' keywords I
    had put in the definition of s_clib_symbol_get_data().  Having found a
    way around that, using a pointer to the symbol structure as the key is
    much faster as it avoids costly string comparisons and allocation of
    heap memory (as well as being slightly more elegant).

:100644 100644 5065bc2... e604a19... M	libgeda/src/s_clib.c

=========
 Changes
=========

commit 53cbd813e6d601f86618aa083d656d7aeccb7705
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date:   Tue Dec 4 22:56:01 2007 +0000

    clib: Speed up caching by using pointer rather than string keys.
    
    The initial version of the symbol cache used the symbol name as a
    string as the key, mostly because of the obnoxious 'const' keywords I
    had put in the definition of s_clib_symbol_get_data().  Having found a
    way around that, using a pointer to the symbol structure as the key is
    much faster as it avoids costly string comparisons and allocation of
    heap memory (as well as being slightly more elegant).

diff --git a/libgeda/src/s_clib.c b/libgeda/src/s_clib.c
index 5065bc2..e604a19 100644
--- a/libgeda/src/s_clib.c
+++ b/libgeda/src/s_clib.c
@@ -207,8 +207,8 @@ struct _CLibSymbol {
 /*! Symbol data cache entry */
 typedef struct _CacheEntry CacheEntry;
 struct _CacheEntry {
-  /*! Symbol name */
-  gchar *name;
+  /*! Pointer to symbol */
+  CLibSymbol *ptr;
   /*! Symbol data */
   gchar *data;
   /*! Last access */
@@ -278,9 +278,9 @@ void s_clib_init ()
     s_clib_flush_symbol_cache();
   } else {
     clib_symbol_cache =
-      g_hash_table_new_full ((GHashFunc) g_str_hash,
-                             (GEqualFunc) g_str_equal,
-                             (GDestroyNotify) g_free,
+      g_hash_table_new_full ((GHashFunc) g_direct_hash,
+                             (GEqualFunc) g_direct_equal,
+                             NULL,
                              (GDestroyNotify) free_symbol_cache_entry);
   }
 }
@@ -311,7 +311,6 @@ static void free_symbol_cache_entry (gpointer data)
 {
   CacheEntry *entry = data;
   g_return_if_fail (entry != NULL);
-  g_free (entry->name);
   g_free (entry->data);
   g_free (entry);
 }
@@ -1153,13 +1152,17 @@ gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
 {
   CacheEntry *cached;
   gchar *data;
+  gpointer symptr;
   gint n;
 
   g_return_val_if_fail ((symbol != NULL), NULL);
   g_return_val_if_fail ((symbol->source != NULL), NULL);
 
+  /* Trickery to bypass effects of const */
+  symptr = (gpointer) symbol;
+
   /* First, try the cache. */
-  cached = g_hash_table_lookup (clib_symbol_cache, symbol->name);
+  cached = g_hash_table_lookup (clib_symbol_cache, symptr);
   if (cached != NULL) {
     cached->accessed = time(NULL);
     return g_strdup(cached->data);
@@ -1187,10 +1190,10 @@ gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
 
   /* Cache the symbol data */
   cached = g_new (CacheEntry, 1);
-  cached->name = g_strdup (symbol->name);
+  cached->ptr = (CLibSymbol *) symptr;
   cached->data = g_strdup (data);
   cached->accessed = time (NULL);
-  g_hash_table_insert (clib_symbol_cache, g_strdup(symbol->name), cached);
+  g_hash_table_insert (clib_symbol_cache, symptr, cached);
 
   /* Clean out the cache if it's too full */
   n = g_hash_table_size (clib_symbol_cache);
@@ -1199,7 +1202,7 @@ gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
       g_hash_table_foreach (clib_symbol_cache,
                             (GHFunc) cache_find_oldest,
                             &cached);
-      g_hash_table_remove (clib_symbol_cache, cached->name);
+      g_hash_table_remove (clib_symbol_cache, cached->ptr);
     }
   }
 




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs