Bug 560419 – Cache includes when parsing

Keep track of all modules parsed within a GIrParser, and when a
module is referenced a second time, use the existing parsed copy
instead of reparsing.

svn path=/trunk/; revision=906
This commit is contained in:
Owen Taylor 2008-11-12 17:17:15 +00:00
parent 9a36a18939
commit 7fa1ffa6e7

View File

@ -31,7 +31,7 @@
struct _GIrParser
{
gchar **includes;
GList *include_modules; /* All previously parsed include modules */
GList *parsed_modules; /* All previously parsed modules */
};
typedef enum
@ -145,9 +145,14 @@ g_ir_parser_new (void)
void
g_ir_parser_free (GIrParser *parser)
{
GList *l;
if (parser->includes)
g_strfreev (parser->includes);
for (l = parser->parsed_modules; l; l = l->next)
g_ir_module_free (l->data);
g_slice_free (GIrParser, parser);
}
@ -2206,7 +2211,7 @@ parse_include (GMarkupParseContext *context,
GList *modules;
GList *l;
for (l = ctx->include_modules; l; l = l->next)
for (l = ctx->parser->parsed_modules; l; l = l->next)
{
GIrModule *m = l->data;
@ -2214,6 +2219,8 @@ parse_include (GMarkupParseContext *context,
{
if (strcmp (m->version, version) == 0)
{
ctx->include_modules = g_list_prepend (ctx->include_modules, m);
return TRUE;
}
else
@ -3054,6 +3061,9 @@ g_ir_parser_parse_string (GIrParser *parser,
if (!g_markup_parse_context_end_parse (context, error))
goto out;
parser->parsed_modules = g_list_concat (g_list_copy (ctx.modules),
parser->parsed_modules);
out:
if (ctx.modules == NULL)