From 43afc9178b105ad972bff9d3d2338926486c7a6f Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Wed, 6 Feb 2008 21:56:06 +0100 Subject: [PATCH] dbghelp: Attempt to cache some basic symbol types for easier and faster code. --- dlls/dbghelp/dwarf.c | 47 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c index 6aae3972bbe..aee3dea39c0 100644 --- a/dlls/dbghelp/dwarf.c +++ b/dlls/dbghelp/dwarf.c @@ -167,6 +167,13 @@ typedef struct dwarf2_traverse_context_s unsigned char word_size; } dwarf2_traverse_context_t; +/* symt_cache indexes */ +#define sc_void 0 +#define sc_int1 1 +#define sc_int2 2 +#define sc_int4 3 +#define sc_num 4 + typedef struct dwarf2_parse_context_s { const dwarf2_section_t* sections; @@ -179,6 +186,7 @@ typedef struct dwarf2_parse_context_s unsigned long load_offset; unsigned long ref_offset; unsigned char word_size; + struct symt* symt_cache[sc_num]; /* void, int1, int2, int4 */ } dwarf2_parse_context_t; /* stored in the dbghelp's module internal structure for later reuse */ @@ -932,7 +940,7 @@ static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx, struct attribute size; struct attribute encoding; enum BasicType bt; - + int cache_idx = -1; if (di->symt) return di->symt; TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di)); @@ -956,6 +964,25 @@ static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx, default: bt = btNoType; break; } di->symt = &symt_new_basic(ctx->module, bt, name.u.string, size.u.uvalue)->symt; + switch (bt) + { + case btVoid: + assert(size.u.uvalue == 0); + cache_idx = sc_void; + break; + case btInt: + switch (size.u.uvalue) + { + case 1: cache_idx = sc_int1; break; + case 2: cache_idx = sc_int2; break; + case 4: cache_idx = sc_int4; break; + } + break; + default: break; + } + if (!ctx->symt_cache[cache_idx]) + ctx->symt_cache[cache_idx] = di->symt; + if (di->abbrev->have_child) FIXME("Unsupported children\n"); return di->symt; } @@ -991,8 +1018,10 @@ static struct symt* dwarf2_parse_pointer_type(dwarf2_parse_context_t* ctx, if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0; if (!(ref_type = dwarf2_lookup_type(ctx, di))) - ref_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; - + { + ref_type = ctx->symt_cache[sc_void]; + assert(ref_type); + } di->symt = &symt_new_pointer(ctx->module, ref_type)->symt; if (di->abbrev->have_child) FIXME("Unsupported children\n"); return di->symt; @@ -1564,7 +1593,10 @@ static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx, is_decl.u.uvalue = 0; if (!(ret_type = dwarf2_lookup_type(ctx, di))) - ret_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; + { + ret_type = ctx->symt_cache[sc_void]; + assert(ret_type); + } /* FIXME: assuming C source code */ sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C); @@ -1657,7 +1689,10 @@ static struct symt* dwarf2_parse_subroutine_type(dwarf2_parse_context_t* ctx, TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di)); if (!(ret_type = dwarf2_lookup_type(ctx, di))) - ret_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; + { + ret_type = ctx->symt_cache[sc_void]; + assert(ret_type); + } /* FIXME: assuming C source code */ sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C); @@ -1979,6 +2014,8 @@ static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections, ctx.thunks = thunks; ctx.load_offset = load_offset; ctx.ref_offset = comp_unit_cursor - sections[section_debug].address; + memset(ctx.symt_cache, 0, sizeof(ctx.symt_cache)); + ctx.symt_cache[sc_void] = &symt_new_basic(module, btVoid, "void", 0)->symt; traverse.start_data = comp_unit_cursor + sizeof(dwarf2_comp_unit_stream_t); traverse.data = traverse.start_data;