Add a cache of the text section.

2006-10-08  Soren Sandmann  <sandmann@redhat.com>

	* elfparser.c (struct ElfParser): Add a cache of the text section.

	* binparser.c (struct BinParser): Add a cache of a bin record to
	get rid of malloc()/free() overhead.

	* elfparser.c (struct ElfSym): Cache the size of the symbol
This commit is contained in:
Soren Sandmann
2006-10-08 20:14:25 +00:00
committed by Søren Sandmann Pedersen
parent 86810e63a5
commit 0cf636d8fe
4 changed files with 60 additions and 38 deletions

View File

@ -35,6 +35,9 @@ struct BinParser
gsize offset;
const guchar * data;
gsize length;
gboolean cache_in_use;
BinRecord cache;
};
BinParser *
@ -46,6 +49,7 @@ bin_parser_new (const guchar *data,
parser->offset = 0;
parser->data = data;
parser->length = length;
parser->cache_in_use = FALSE;
return parser;
}
@ -359,18 +363,33 @@ bin_parser_get_record (BinParser *parser,
BinFormat *format,
gsize offset)
{
BinRecord *record = g_new0 (BinRecord, 1);
BinRecord *record;
if (!parser->cache_in_use)
{
parser->cache_in_use = TRUE;
record = &(parser->cache);
}
else
{
record = g_new0 (BinRecord, 1);
}
record->parser = parser;
record->index = 0;
record->offset = offset;
record->format = format;
return record;
}
void
bin_record_free (BinRecord *record)
{
g_free (record);
if (record == &(record->parser->cache))
record->parser->cache_in_use = FALSE;
else
g_free (record);
}
guint64