Markus Amsler : dbghelp: Late init hash_table.

Alexandre Julliard julliard at wine.codeweavers.com
Tue May 15 14:02:20 CDT 2007


Module: wine
Branch: master
Commit: 6f8a67f01825e765de8303d1fbec7a5d07fafcae
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6f8a67f01825e765de8303d1fbec7a5d07fafcae

Author: Markus Amsler <markus.amsler at oribi.org>
Date:   Tue May 15 02:05:21 2007 +0200

dbghelp: Late init hash_table.

---

 dlls/dbghelp/dbghelp_private.h |    1 +
 dlls/dbghelp/storage.c         |   26 +++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index a108360..99b8b54 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -83,6 +83,7 @@ struct hash_table
     unsigned                    num_elts;
     unsigned                    num_buckets;
     struct hash_table_elt**     buckets;
+    struct pool*                pool;
 };
 
 void     hash_table_init(struct pool* pool, struct hash_table* ht,
diff --git a/dlls/dbghelp/storage.c b/dlls/dbghelp/storage.c
index 91cb0ed..88c9b1d 100644
--- a/dlls/dbghelp/storage.c
+++ b/dlls/dbghelp/storage.c
@@ -52,21 +52,27 @@ void pool_destroy(struct pool* pool)
 #ifdef USE_STATS
     unsigned    alloc, used, num;
     
-    for (alloc = used = num = 0, arena = pool->first; arena; arena = arena->next)
+    alloc = used = num = 0;
+    arena = pool->first;
+    while (arena)
     {
         alloc += pool->arena_size;
         used += arena->current - (char*)arena;
         num++;
+        arena = arena->next;
     }
+    if (alloc == 0) alloc = 1;      /* avoid division by zero */
     FIXME("STATS: pool %p has allocated %u kbytes, used %u kbytes in %u arenas,\n"
           "\t\t\t\tnon-allocation ratio: %.2f%%\n",
           pool, alloc >> 10, used >> 10, num, 100.0 - (float)used / (float)alloc * 100.0);
 #endif
 
-    for (arena = pool->first; arena; arena = next)
+    arena = pool->first;
+    while (arena)
     {
         next = arena->next;
         HeapFree(GetProcessHeap(), 0, arena);
+        arena = next;
     }
     pool_init(pool, 0);
 }
@@ -310,10 +316,9 @@ unsigned hash_table_hash(const char* name, unsigned num_buckets)
 void hash_table_init(struct pool* pool, struct hash_table* ht, unsigned num_buckets)
 {
     ht->num_elts = 0;
-    ht->buckets = pool_alloc(pool, num_buckets * sizeof(struct hash_table_elt*));
-    assert(ht->buckets);
     ht->num_buckets = num_buckets;
-    memset(ht->buckets, 0, num_buckets * sizeof(struct hash_table_elt*));
+    ht->pool = pool;
+    ht->buckets = NULL;
 }
 
 void hash_table_destroy(struct hash_table* ht)
@@ -358,6 +363,13 @@ void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt)
     unsigned                    hash = hash_table_hash(elt->name, ht->num_buckets);
     struct hash_table_elt**     p;
 
+    if (!ht->buckets)
+    {
+        ht->buckets = pool_alloc(ht->pool, ht->num_buckets * sizeof(struct hash_table_elt*));
+        assert(ht->buckets);
+        memset(ht->buckets, 0, ht->num_buckets * sizeof(struct hash_table_elt*));
+    }
+
     /* in some cases, we need to get back the symbols of same name in the order
      * in which they've been inserted. So insert new elements at the end of the list.
      */
@@ -372,6 +384,8 @@ void* hash_table_find(const struct hash_table* ht, const char* name)
     unsigned                    hash = hash_table_hash(name, ht->num_buckets);
     struct hash_table_elt*      elt;
 
+    if(!ht->buckets) return NULL;
+
     for (elt = ht->buckets[hash]; elt; elt = elt->next)
         if (!strcmp(name, elt->name)) return elt;
     return NULL;
@@ -396,6 +410,8 @@ void hash_table_iter_init(const struct hash_table* ht,
 
 void* hash_table_iter_up(struct hash_table_iter* hti)
 {
+    if(!hti->ht->buckets) return NULL;
+
     if (hti->element) hti->element = hti->element->next;
     while (!hti->element && hti->index < hti->last) 
         hti->element = hti->ht->buckets[++hti->index];




More information about the wine-cvs mailing list