[PATCH 2/4] [DbgHelp]: hash table & number of elements
Eric Pouech
eric.pouech at wanadoo.fr
Tue Dec 5 15:13:27 CST 2006
- added a field to the hash table to store the
number of elements in the hash table
- make use of it to get rid to module_compute_num_syms
A+
---
dlls/dbghelp/dbghelp_private.h | 2 +-
dlls/dbghelp/module.c | 16 ++--------------
dlls/dbghelp/storage.c | 9 +++++----
dlls/dbghelp/symbol.c | 3 ++-
4 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index f575bcf..9c6abc0 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -82,6 +82,7 @@ struct hash_table_elt
struct hash_table
{
+ unsigned num_elts;
unsigned num_buckets;
struct hash_table_elt** buckets;
};
@@ -422,7 +423,6 @@ extern int elf_is_in_thunk_area
extern DWORD WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS* addr);
/* module.c */
-extern int module_compute_num_syms(struct module* module);
extern struct module*
module_find_by_addr(const struct process* pcs, unsigned long addr,
enum module_type type);
diff --git a/dlls/dbghelp/module.c b/dlls/dbghelp/module.c
index 1b84121..a58ee6f 100644
--- a/dlls/dbghelp/module.c
+++ b/dlls/dbghelp/module.c
@@ -284,7 +284,7 @@ BOOL module_get_debug(struct module_pair
}
if (!ret) pair->effective->module.SymType = SymNone;
assert(pair->effective->module.SymType != SymDeferred);
- module_compute_num_syms(pair->effective);
+ pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
}
return pair->effective->module.SymType != SymNone;
}
@@ -372,18 +372,6 @@ enum module_type module_get_type_by_name
return DMT_PE;
}
-int module_compute_num_syms(struct module* module)
-{
- struct hash_table_iter hti;
- void* ptr;
-
- module->module.NumSyms = 0;
- hash_table_iter_init(&module->ht_symbols, &hti, NULL);
- while ((ptr = hash_table_iter_up(&hti)))
- module->module.NumSyms++;
- return module->module.NumSyms;
-}
-
/***********************************************************************
* SymLoadModule (DBGHELP.@)
*/
@@ -429,7 +417,7 @@ DWORD WINAPI SymLoadModule(HANDLE hProce
WARN("Couldn't locate %s\n", ImageName);
return 0;
}
- module_compute_num_syms(module);
+ module->module.NumSyms = module->ht_symbols.num_elts;
done:
/* by default pe_load_module fills module.ModuleName from a derivation
* of ImageName. Overwrite it, if we have better information
diff --git a/dlls/dbghelp/storage.c b/dlls/dbghelp/storage.c
index 3aef566..3aee97d 100644
--- a/dlls/dbghelp/storage.c
+++ b/dlls/dbghelp/storage.c
@@ -327,6 +327,7 @@ unsigned hash_table_hash(const char* nam
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;
@@ -338,7 +339,7 @@ void hash_table_destroy(struct hash_tabl
#if defined(USE_STATS)
int i;
unsigned len;
- unsigned num = 0, min = 0xffffffff, max = 0, sq = 0;
+ unsigned min = 0xffffffff, max = 0, sq = 0;
struct hash_table_elt* elt;
double mean, variance;
@@ -347,13 +348,12 @@ #if defined(USE_STATS)
for (len = 0, elt = ht->buckets[i]; elt; elt = elt->next) len++;
if (len < min) min = len;
if (len > max) max = len;
- num += len;
sq += len * len;
}
- mean = (double)num / ht->num_buckets;
+ mean = (double)ht->num_elts / ht->num_buckets;
variance = (double)sq / ht->num_buckets - mean * mean;
FIXME("STATS: elts[num:%-4u size:%u mean:%f] buckets[min:%-4u variance:%+f max:%-4u]\n",
- num, ht->num_buckets, mean, min, variance, max);
+ ht->num_elts, ht->num_buckets, mean, min, variance, max);
#if 1
for (i = 0; i < ht->num_buckets; i++)
{
@@ -382,6 +382,7 @@ void hash_table_add(struct hash_table* h
for (p = &ht->buckets[hash]; *p; p = &((*p)->next));
*p = elt;
elt->next = NULL;
+ ht->num_elts++;
}
void* hash_table_find(const struct hash_table* ht, const char* name)
diff --git a/dlls/dbghelp/symbol.c b/dlls/dbghelp/symbol.c
index f4b0612..b9e2f2a 100644
--- a/dlls/dbghelp/symbol.c
+++ b/dlls/dbghelp/symbol.c
@@ -623,7 +623,8 @@ static BOOL resort_symbols(struct module
struct symt_ht* sym;
struct hash_table_iter hti;
- if (!module_compute_num_syms(module)) return FALSE;
+ if (!(module->module.NumSyms = module->ht_symbols.num_elts))
+ return FALSE;
if (module->addr_sorttab)
module->addr_sorttab = HeapReAlloc(GetProcessHeap(), 0,
More information about the wine-patches
mailing list