mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-15 20:18:05 +02: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 *version;
|
||||||
char *shared_library;
|
char *shared_library;
|
||||||
char *c_prefix;
|
char *c_prefix;
|
||||||
GList *dependencies; /* (owned) */
|
GPtrArray *dependencies; /* (owned) */
|
||||||
GList *entries;
|
GList *entries;
|
||||||
|
|
||||||
/* All modules that are included directly or indirectly */
|
/* 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);
|
gi_ir_node_free ((GIIrNode *)e->data);
|
||||||
|
|
||||||
g_list_free (module->entries);
|
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);
|
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
|
/* Serialize dependencies into one string; this is convenient
|
||||||
* and not a major change to the typelib format. */
|
* and not a major change to the typelib format. */
|
||||||
{
|
if (module->dependencies->len)
|
||||||
GString *dependencies_str = g_string_new ("");
|
{
|
||||||
GList *link;
|
GString *dependencies_str = g_string_new (NULL);
|
||||||
for (link = module->dependencies; link; link = link->next)
|
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))
|
if (!strcmp (dependency, module->name))
|
||||||
continue;
|
continue;
|
||||||
g_string_append (dependencies_str, dependency);
|
g_string_append (dependencies_str, dependency);
|
||||||
if (link->next)
|
if (i > 1)
|
||||||
g_string_append_c (dependencies_str, '|');
|
g_string_append_c (dependencies_str, '|');
|
||||||
}
|
}
|
||||||
dependencies = g_string_free (dependencies_str, FALSE);
|
dependencies = g_string_free (dependencies_str, FALSE);
|
||||||
if (!dependencies[0])
|
if (dependencies && !dependencies[0])
|
||||||
{
|
{
|
||||||
g_free (dependencies);
|
g_free (dependencies);
|
||||||
dependencies = NULL;
|
dependencies = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dependencies = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
gi_ir_node_init_stats ();
|
gi_ir_node_init_stats ();
|
||||||
@ -378,8 +382,8 @@ gi_ir_module_build_typelib (GIIrModule *module)
|
|||||||
nodes_with_attributes = NULL;
|
nodes_with_attributes = NULL;
|
||||||
n_entries = g_list_length (module->entries);
|
n_entries = g_list_length (module->entries);
|
||||||
|
|
||||||
g_message ("%d entries (%d local), %d dependencies", n_entries, n_local_entries,
|
g_message ("%d entries (%d local), %u dependencies", n_entries, n_local_entries,
|
||||||
g_list_length (module->dependencies));
|
module->dependencies ? module->dependencies->len : 0);
|
||||||
|
|
||||||
dir_size = n_entries * sizeof (DirEntry);
|
dir_size = n_entries * sizeof (DirEntry);
|
||||||
size = header_size + dir_size;
|
size = header_size + dir_size;
|
||||||
|
@ -120,7 +120,7 @@ struct _ParseContext
|
|||||||
|
|
||||||
GList *modules;
|
GList *modules;
|
||||||
GList *include_modules;
|
GList *include_modules;
|
||||||
GList *dependencies;
|
GPtrArray *dependencies;
|
||||||
GHashTable *aliases;
|
GHashTable *aliases;
|
||||||
GHashTable *disguised_structures;
|
GHashTable *disguised_structures;
|
||||||
GHashTable *pointer_structures;
|
GHashTable *pointer_structures;
|
||||||
@ -3101,9 +3101,8 @@ start_element_handler (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->dependencies = g_list_prepend (ctx->dependencies,
|
g_ptr_array_insert (ctx->dependencies, 0,
|
||||||
g_strdup_printf ("%s-%s", name, version));
|
g_strdup_printf ("%s-%s", name, version));
|
||||||
|
|
||||||
|
|
||||||
state_switch (ctx, STATE_INCLUDE);
|
state_switch (ctx, STATE_INCLUDE);
|
||||||
goto out;
|
goto out;
|
||||||
@ -3191,9 +3190,12 @@ start_element_handler (GMarkupParseContext *context,
|
|||||||
ctx->include_modules = NULL;
|
ctx->include_modules = NULL;
|
||||||
|
|
||||||
ctx->modules = g_list_append (ctx->modules, ctx->current_module);
|
ctx->modules = g_list_append (ctx->modules, ctx->current_module);
|
||||||
g_clear_list (&ctx->current_module->dependencies, g_free);
|
|
||||||
ctx->current_module->dependencies =
|
if (ctx->current_module->dependencies != ctx->dependencies)
|
||||||
g_list_copy_deep (ctx->dependencies, (GCopyFunc) g_strdup, NULL);
|
{
|
||||||
|
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);
|
state_switch (ctx, STATE_NAMESPACE);
|
||||||
goto out;
|
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.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.pointer_structures = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||||
ctx.type_depth = 0;
|
ctx.type_depth = 0;
|
||||||
ctx.dependencies = NULL;
|
ctx.dependencies = g_ptr_array_new_with_free_func (g_free);
|
||||||
ctx.current_module = NULL;
|
ctx.current_module = NULL;
|
||||||
|
|
||||||
context = g_markup_parse_context_new (&firstpass_parser, 0, &ctx, 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_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);
|
g_markup_parse_context_free (context);
|
||||||
|
|
||||||
if (module)
|
if (module)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user