From 2e2e60620896753ff9a6b1a93a6bedadec8e5f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 10 May 2024 18:18:19 +0200 Subject: [PATCH] girparser: Simplify the ownership of context modules and parsed ones There's no need to copy the list of modules and free it again, we can just handle this by moving the modules to the parser promptly. --- girepository/girparser.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/girepository/girparser.c b/girepository/girparser.c index df3983a82..091b947c6 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -3775,6 +3775,7 @@ gi_ir_parser_parse_string (GIIrParser *parser, { ParseContext ctx = { 0 }; GMarkupParseContext *context; + GIIrModule *module = NULL; ctx.parser = parser; ctx.state = STATE_START; @@ -3806,12 +3807,15 @@ gi_ir_parser_parse_string (GIIrParser *parser, if (!g_markup_parse_context_end_parse (context, error)) goto out; - parser->parsed_modules = g_list_concat (g_list_copy (ctx.modules), + if (ctx.modules) + module = ctx.modules->data; + + parser->parsed_modules = g_list_concat (g_steal_pointer (&ctx.modules), parser->parsed_modules); out: - if (ctx.modules == NULL) + if (module == NULL) { /* An error occurred before we created a module, so we haven't * transferred ownership of these hash tables to the module. @@ -3827,13 +3831,8 @@ gi_ir_parser_parse_string (GIIrParser *parser, g_clear_list (&ctx.dependencies, g_free); g_markup_parse_context_free (context); - if (ctx.modules) - { - GIIrModule *module = ctx.modules->data; - - g_clear_list (&ctx.modules, NULL); - return module; - } + if (module) + return module; if (error && *error == NULL) g_set_error (error,