mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
gdataset: inline g_datalist_clear_i() in g_dataset_destroy_internal()
g_datalist_clear_i() had only one caller, altough the code comment made it sound as if in the past there were more. A function that has only one caller, and then needs a code comment to explain the context in which it is called, makes the code more complicated than necessary. Especially since the function expects to be called with a global lock held, and then unlocks and relocks. Spreading such things to another function (which is only used once) makes code harder to follow. Inline the function, so that we can see all the (trivial) code at one place.
This commit is contained in:
parent
8439b589ec
commit
e931162348
@ -104,7 +104,6 @@ struct _GDataset
|
||||
|
||||
/* --- prototypes --- */
|
||||
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
|
||||
static inline void g_datalist_clear_i (GData **datalist);
|
||||
static void g_dataset_destroy_internal (GDataset *dataset);
|
||||
static inline gpointer g_data_set_internal (GData **datalist,
|
||||
GQuark key_id,
|
||||
@ -152,33 +151,6 @@ g_datalist_unlock_and_set (GData **datalist, gpointer ptr)
|
||||
g_pointer_bit_unlock_and_set ((void **) datalist, DATALIST_LOCK_BIT, ptr, G_DATALIST_FLAGS_MASK_INTERNAL);
|
||||
}
|
||||
|
||||
/* Called with the datalist lock held, or the dataset global
|
||||
* lock for dataset lists
|
||||
*/
|
||||
static void
|
||||
g_datalist_clear_i (GData **datalist)
|
||||
{
|
||||
GData *data;
|
||||
guint i;
|
||||
|
||||
data = G_DATALIST_GET_POINTER (datalist);
|
||||
G_DATALIST_SET_POINTER (datalist, NULL);
|
||||
|
||||
if (data)
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
for (i = 0; i < data->len; i++)
|
||||
{
|
||||
if (data->data[i].data && data->data[i].destroy)
|
||||
data->data[i].destroy (data->data[i].data);
|
||||
}
|
||||
G_LOCK (g_dataset_global);
|
||||
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* g_datalist_clear: (skip)
|
||||
* @datalist: a datalist.
|
||||
@ -238,6 +210,9 @@ g_dataset_destroy_internal (GDataset *dataset)
|
||||
dataset_location = dataset->location;
|
||||
while (dataset)
|
||||
{
|
||||
GData *data;
|
||||
guint i;
|
||||
|
||||
if (G_DATALIST_GET_POINTER(&dataset->datalist) == NULL)
|
||||
{
|
||||
if (dataset == g_dataset_cached)
|
||||
@ -247,7 +222,22 @@ g_dataset_destroy_internal (GDataset *dataset)
|
||||
break;
|
||||
}
|
||||
|
||||
g_datalist_clear_i (&dataset->datalist);
|
||||
data = G_DATALIST_GET_POINTER (&dataset->datalist);
|
||||
G_DATALIST_SET_POINTER (&dataset->datalist, NULL);
|
||||
|
||||
if (data)
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
for (i = 0; i < data->len; i++)
|
||||
{
|
||||
if (data->data[i].data && data->data[i].destroy)
|
||||
data->data[i].destroy (data->data[i].data);
|
||||
}
|
||||
G_LOCK (g_dataset_global);
|
||||
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user