dbghelp: Late init hash_table.
This commit is contained in:
parent
8bc839a816
commit
6f8a67f018
|
@ -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,
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue