From a1a879363d63f12bdfa59b2f38bd3a731ba01d24 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 5 Dec 2006 22:13:27 +0100 Subject: [PATCH] dbghelp: 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. --- 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 f575bcf2223..9c6abc01cf9 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(unsigned long addr, const struct elf_th 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 1b84121998e..a58ee6f9865 100644 --- a/dlls/dbghelp/module.c +++ b/dlls/dbghelp/module.c @@ -284,7 +284,7 @@ BOOL module_get_debug(struct module_pair* 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(const char* 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 hProcess, HANDLE hFile, const char* ImageName, 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 3aef566d4b9..3aee97d9071 100644 --- a/dlls/dbghelp/storage.c +++ b/dlls/dbghelp/storage.c @@ -327,6 +327,7 @@ 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; @@ -338,7 +339,7 @@ void hash_table_destroy(struct hash_table* ht) #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 @@ void hash_table_destroy(struct hash_table* ht) 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* ht, struct hash_table_elt* elt) 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 f4b06122596..b9e2f2a79c4 100644 --- a/dlls/dbghelp/symbol.c +++ b/dlls/dbghelp/symbol.c @@ -623,7 +623,8 @@ static BOOL resort_symbols(struct module* 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, -- 2.11.4.GIT