mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-05 17:06:18 +01:00
girepository/girparser,girmodule: Use a GPtrArray to hold the dependencies
It's just better than a list of strings for various reasons, but mostly here it allows also to avoid copying the lists but making the ownership clearer through references
This commit is contained in:
parent
2e2e606208
commit
b27fbf503b
@ -47,7 +47,7 @@ struct _GIIrModule
|
||||
char *version;
|
||||
char *shared_library;
|
||||
char *c_prefix;
|
||||
GList *dependencies; /* (owned) */
|
||||
GPtrArray *dependencies; /* (owned) */
|
||||
GList *entries;
|
||||
|
||||
/* All modules that are included directly or indirectly */
|
||||
|
@ -83,7 +83,7 @@ gi_ir_module_free (GIIrModule *module)
|
||||
gi_ir_node_free ((GIIrNode *)e->data);
|
||||
|
||||
g_list_free (module->entries);
|
||||
g_clear_list (&module->dependencies, g_free);
|
||||
g_clear_pointer (&module->dependencies, g_ptr_array_unref);
|
||||
|
||||
g_list_free (module->include_modules);
|
||||
|
||||
@ -351,25 +351,29 @@ gi_ir_module_build_typelib (GIIrModule *module)
|
||||
|
||||
/* Serialize dependencies into one string; this is convenient
|
||||
* and not a major change to the typelib format. */
|
||||
if (module->dependencies->len)
|
||||
{
|
||||
GString *dependencies_str = g_string_new ("");
|
||||
GList *link;
|
||||
for (link = module->dependencies; link; link = link->next)
|
||||
GString *dependencies_str = g_string_new (NULL);
|
||||
for (guint i = module->dependencies->len; i > 0; --i)
|
||||
{
|
||||
const char *dependency = link->data;
|
||||
const char *dependency = g_ptr_array_index (module->dependencies, i-1);
|
||||
if (!strcmp (dependency, module->name))
|
||||
continue;
|
||||
g_string_append (dependencies_str, dependency);
|
||||
if (link->next)
|
||||
if (i > 1)
|
||||
g_string_append_c (dependencies_str, '|');
|
||||
}
|
||||
dependencies = g_string_free (dependencies_str, FALSE);
|
||||
if (!dependencies[0])
|
||||
if (dependencies && !dependencies[0])
|
||||
{
|
||||
g_free (dependencies);
|
||||
dependencies = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies = NULL;
|
||||
}
|
||||
|
||||
restart:
|
||||
gi_ir_node_init_stats ();
|
||||
@ -378,8 +382,8 @@ gi_ir_module_build_typelib (GIIrModule *module)
|
||||
nodes_with_attributes = NULL;
|
||||
n_entries = g_list_length (module->entries);
|
||||
|
||||
g_message ("%d entries (%d local), %d dependencies", n_entries, n_local_entries,
|
||||
g_list_length (module->dependencies));
|
||||
g_message ("%d entries (%d local), %u dependencies", n_entries, n_local_entries,
|
||||
module->dependencies ? module->dependencies->len : 0);
|
||||
|
||||
dir_size = n_entries * sizeof (DirEntry);
|
||||
size = header_size + dir_size;
|
||||
|
@ -120,7 +120,7 @@ struct _ParseContext
|
||||
|
||||
GList *modules;
|
||||
GList *include_modules;
|
||||
GList *dependencies;
|
||||
GPtrArray *dependencies;
|
||||
GHashTable *aliases;
|
||||
GHashTable *disguised_structures;
|
||||
GHashTable *pointer_structures;
|
||||
@ -3101,10 +3101,9 @@ start_element_handler (GMarkupParseContext *context,
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->dependencies = g_list_prepend (ctx->dependencies,
|
||||
g_ptr_array_insert (ctx->dependencies, 0,
|
||||
g_strdup_printf ("%s-%s", name, version));
|
||||
|
||||
|
||||
state_switch (ctx, STATE_INCLUDE);
|
||||
goto out;
|
||||
}
|
||||
@ -3191,9 +3190,12 @@ start_element_handler (GMarkupParseContext *context,
|
||||
ctx->include_modules = NULL;
|
||||
|
||||
ctx->modules = g_list_append (ctx->modules, ctx->current_module);
|
||||
g_clear_list (&ctx->current_module->dependencies, g_free);
|
||||
ctx->current_module->dependencies =
|
||||
g_list_copy_deep (ctx->dependencies, (GCopyFunc) g_strdup, NULL);
|
||||
|
||||
if (ctx->current_module->dependencies != ctx->dependencies)
|
||||
{
|
||||
g_clear_pointer (&ctx->current_module->dependencies, g_ptr_array_unref);
|
||||
ctx->current_module->dependencies = g_ptr_array_ref (ctx->dependencies);
|
||||
}
|
||||
|
||||
state_switch (ctx, STATE_NAMESPACE);
|
||||
goto out;
|
||||
@ -3786,7 +3788,7 @@ gi_ir_parser_parse_string (GIIrParser *parser,
|
||||
ctx.disguised_structures = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
ctx.pointer_structures = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
ctx.type_depth = 0;
|
||||
ctx.dependencies = NULL;
|
||||
ctx.dependencies = g_ptr_array_new_with_free_func (g_free);
|
||||
ctx.current_module = NULL;
|
||||
|
||||
context = g_markup_parse_context_new (&firstpass_parser, 0, &ctx, NULL);
|
||||
@ -3828,7 +3830,7 @@ gi_ir_parser_parse_string (GIIrParser *parser,
|
||||
}
|
||||
|
||||
g_clear_slist (&ctx.node_stack, NULL);
|
||||
g_clear_list (&ctx.dependencies, g_free);
|
||||
g_clear_pointer (&ctx.dependencies, g_ptr_array_unref);
|
||||
g_markup_parse_context_free (context);
|
||||
|
||||
if (module)
|
||||
|
Loading…
Reference in New Issue
Block a user