Commit 8bc839a8 authored by Markus Amsler's avatar Markus Amsler Committed by Alexandre Julliard

dbghelp: Speed up vector iteration by directly using for().

parent a2968c8f
......@@ -60,9 +60,6 @@ void vector_init(struct vector* v, unsigned elt_sz, unsigned bucket_sz);
unsigned vector_length(const struct vector* v);
void* vector_at(const struct vector* v, unsigned pos);
void* vector_add(struct vector* v, struct pool* pool);
/*void vector_pool_normalize(struct vector* v, struct pool* pool); */
void* vector_iter_up(const struct vector* v, const void* elt);
void* vector_iter_down(const struct vector* v, const void* elt);
struct sparse_array
{
......
......@@ -1004,8 +1004,8 @@ static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
struct symt* ref_type;
struct symt* idx_type = NULL;
struct attribute min, max, cnt;
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
if (di->symt) return di->symt;
......@@ -1018,9 +1018,9 @@ static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
}
ref_type = dwarf2_lookup_type(ctx, di);
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
case DW_TAG_subrange_type:
......@@ -1162,12 +1162,12 @@ static struct symt* dwarf2_parse_udt_type(dwarf2_parse_context_t* ctx,
if (di->abbrev->have_child) /** any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -1227,13 +1227,13 @@ static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx,
if (di->abbrev->have_child) /* any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
/* FIXME: should we use the sibling stuff ?? */
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -1411,12 +1411,12 @@ static void dwarf2_parse_inlined_subroutine(dwarf2_subprogram_t* subpgm,
if (di->abbrev->have_child) /** any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -1464,12 +1464,12 @@ static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t* subpgm,
if (di->abbrev->have_child) /** any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -1581,12 +1581,12 @@ static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx,
if (di->abbrev->have_child) /** any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -1653,12 +1653,12 @@ static struct symt* dwarf2_parse_subroutine_type(dwarf2_parse_context_t* ctx,
if (di->abbrev->have_child) /** any interest to not have child ? */
{
dwarf2_debug_info_t** pchild = NULL;
dwarf2_debug_info_t* child;
int i;
while ((pchild = vector_iter_up(&di->children, pchild)))
for (i=0; i<vector_length(&di->children); i++)
{
child = *pchild;
child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
switch (child->abbrev->tag)
{
......@@ -2005,8 +2005,10 @@ static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections,
if (di->abbrev->have_child)
{
while ((pdi = vector_iter_up(&di->children, pdi)))
int i;
for (i=0; i<vector_length(&di->children); i++)
{
pdi = vector_at(&di->children, i);
dwarf2_load_one_entry(&ctx, *pdi, (struct symt_compiland*)di->symt);
}
}
......@@ -2059,9 +2061,11 @@ static enum location_error loc_compute_frame(struct process* pcs,
struct location* pframe;
dwarf2_traverse_context_t lctx;
enum location_error err;
int i;
while ((psym = vector_iter_up(&func->vchildren, psym)))
for (i=0; i<vector_length(&func->vchildren); i++)
{
psym = vector_at(&func->vchildren, i);
if ((*psym)->tag == SymTagCustom)
{
pframe = &((struct symt_function_point*)*psym)->loc;
......
......@@ -190,13 +190,15 @@ BOOL WINAPI SymEnumLines(HANDLE hProcess, ULONG64 base, PCSTR compiland,
hash_table_iter_init(&pair.effective->ht_symbols, &hti, NULL);
while ((ptr = hash_table_iter_up(&hti)))
{
int i;
sym = GET_ENTRY(ptr, struct symt_ht, hash_elt);
if (sym->symt.tag != SymTagFunction) continue;
dli = NULL;
sci.FileName[0] = '\0';
while ((dli = vector_iter_up(&((struct symt_function*)sym)->vlines, dli)))
for (i=0; i<vector_length(&((struct symt_function*)sym)->vlines); i++)
{
dli = vector_at(&((struct symt_function*)sym)->vlines, i);
if (dli->is_source_file)
{
file = source_get(pair.effective, dli->u.source_file);
......
......@@ -174,42 +174,6 @@ void* vector_add(struct vector* v, struct pool* pool)
return vector_at(v, ncurr);
}
static unsigned vector_position(const struct vector* v, const void* elt)
{
int i;
for (i = 0; i < v->num_buckets; i++)
{
if (v->buckets[i] <= elt &&
(const char*)elt < (const char*)v->buckets[i] + (v->elt_size << v->shift))
{
return (i << v->shift) +
((const char*)elt - (const char*)v->buckets[i]) / v->elt_size;
}
}
assert(0);
return 0;
}
void* vector_iter_up(const struct vector* v, const void* elt)
{
unsigned pos;
if (!elt) return vector_at(v, 0);
pos = vector_position(v, elt) + 1;
if (pos >= vector_length(v)) return NULL;
return vector_at(v, pos);
}
void* vector_iter_down(const struct vector* v, const void* elt)
{
unsigned pos;
if (!elt) return vector_at(v, vector_length(v) - 1);
pos = vector_position(v, elt);
if (pos == 0) return NULL;
return vector_at(v, pos - 1);
}
/* We construct the sparse array as two vectors (of equal size)
* The first vector (key2index) is the lookup table between the key and
* an index in the second vector (elements)
......
......@@ -253,6 +253,7 @@ void symt_add_func_line(struct module* module, struct symt_function* func,
{
struct line_info* dli;
BOOL last_matches = FALSE;
int i;
if (func == NULL || !(dbghelp_options & SYMOPT_LOAD_LINES)) return;
......@@ -262,9 +263,9 @@ void symt_add_func_line(struct module* module, struct symt_function* func,
assert(func->symt.tag == SymTagFunction);
dli = NULL;
while ((dli = vector_iter_down(&func->vlines, dli)))
for (i=vector_length(&func->vlines)-1; i>=0; i--)
{
dli = vector_at(&func->vlines, i);
if (dli->is_source_file)
{
last_matches = (source_idx == dli->u.source_file);
......@@ -754,13 +755,13 @@ static BOOL symt_enum_locals_helper(struct module_pair* pair,
regex_t* preg, const struct sym_enum* se,
struct symt_function* func, const struct vector* v)
{
struct symt** plsym = NULL;
struct symt* lsym = NULL;
DWORD pc = pair->pcs->ctx_frame.InstructionOffset;
int i;
while ((plsym = vector_iter_up(v, plsym)))
for (i=0; i<vector_length(v); i++)
{
lsym = *plsym;
lsym = *(struct symt**)vector_at(v, i);
switch (lsym->tag)
{
case SymTagBlock:
......@@ -1228,11 +1229,13 @@ BOOL symt_fill_func_line_info(const struct module* module, const struct symt_fun
{
struct line_info* dli = NULL;
BOOL found = FALSE;
int i;
assert(func->symt.tag == SymTagFunction);
while ((dli = vector_iter_down(&func->vlines, dli)))
for (i=vector_length(&func->vlines)-1; i>=0; i--)
{
dli = vector_at(&func->vlines, i);
if (!dli->is_source_file)
{
if (found || dli->u.pc_offset > addr) continue;
......
......@@ -215,10 +215,10 @@ BOOL symt_add_udt_element(struct module* module, struct symt_udt* udt_type,
TRACE_(dbghelp_symt)("Adding %s to UDT %s\n", name, udt_type->hash_elt.name);
if (name)
{
p = NULL;
while ((p = vector_iter_up(&udt_type->vchildren, p)))
int i;
for (i=0; i<vector_length(&udt_type->vchildren); i++)
{
m = (struct symt_data*)*p;
m = *(struct symt_data**)vector_at(&udt_type->vchildren, i);
assert(m);
assert(m->symt.tag == SymTagData);
if (strcmp(m->hash_elt.name, name) == 0)
......@@ -379,8 +379,8 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
SYMBOL_INFO* sym_info = (SYMBOL_INFO*)buffer;
const char* tmp;
struct symt* type;
void* pos = NULL;
DWORD64 size;
int i;
TRACE("(%p %s %p %p)\n",
hProcess, wine_dbgstr_longlong(BaseOfDll), EnumSymbolsCallback,
......@@ -393,9 +393,9 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, ULONG64 BaseOfDll,
sym_info->SizeOfStruct = sizeof(SYMBOL_INFO);
sym_info->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
while ((pos = vector_iter_up(&pair.effective->vtypes, pos)))
for (i=0; i<vector_length(&pair.effective->vtypes); i++)
{
type = *(struct symt**)pos;
type = *(struct symt**)vector_at(&pair.effective->vtypes, i);
sym_info->TypeIndex = (DWORD)type;
sym_info->info = 0; /* FIXME */
symt_get_info(type, TI_GET_LENGTH, &size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment