resources: Consolidate creation of GResource into one place

This commit is contained in:
Christian Persch 2012-02-05 19:55:45 +01:00
parent 04df4d45a4
commit 30e0a1beac

View File

@ -183,6 +183,24 @@ g_resource_unref (GResource *resource)
} }
} }
/*
* g_resource_new_from_table:
* @table: (transfer full): a GvdbTable
*
* Returns: (transfer full): a new #GResource for @table
*/
static GResource *
g_resource_new_from_table (GvdbTable *table)
{
GResource *resource;
resource = g_new (GResource, 1);
resource->ref_count = 1;
resource->table = table;
return resource;
}
/** /**
* g_resource_new_from_data: * g_resource_new_from_data:
* @data: A #GBytes. * @data: A #GBytes.
@ -203,7 +221,6 @@ GResource *
g_resource_new_from_data (GBytes *data, g_resource_new_from_data (GBytes *data,
GError **error) GError **error)
{ {
GResource *resource;
GvdbTable *table; GvdbTable *table;
table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL), table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL),
@ -217,11 +234,7 @@ g_resource_new_from_data (GBytes *data,
if (table == NULL) if (table == NULL)
return NULL; return NULL;
resource = g_new0 (GResource, 1); return g_resource_new_from_table (table);
resource->ref_count = 1;
resource->table = table;
return resource;
} }
/** /**
@ -243,18 +256,13 @@ GResource *
g_resource_load (const gchar *filename, g_resource_load (const gchar *filename,
GError **error) GError **error)
{ {
GResource *resource;
GvdbTable *table; GvdbTable *table;
table = gvdb_table_new (filename, FALSE, error); table = gvdb_table_new (filename, FALSE, error);
if (table == NULL) if (table == NULL)
return NULL; return NULL;
resource = g_new0 (GResource, 1); return g_resource_new_from_table (table);
resource->ref_count = 1;
resource->table = table;
return resource;
} }
static gboolean do_lookup (GResource *resource, static gboolean do_lookup (GResource *resource,