Bug 560419 – Cache includes when parsing
authorOwen Taylor <otaylor@src.gnome.org>
Wed, 12 Nov 2008 17:17:15 +0000 (17:17 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 12 Nov 2008 17:17:15 +0000 (17:17 +0000)
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

ChangeLog
girepository/girparser.c

index 1e4b099..a136487 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-12  Owen Taylor  <otaylor@redhat.com>
+
+       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.
+
 2008-11-12  Owen Taylor  <otaylor@redhat.com>
 
        Fix management of ParseContext.includes_modules (#560419)
index 198d78b..65ba282 100644 (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)