gegl/buffer: use more explicit code for cleanup

This is a revert of the parts of this commit
66dad217, that touched gegl/buffer, some part
of seen performance regression might be the function call overhead of g_free
which will be skipped when conditions for NULL fails.
parent cfbce3db
......@@ -63,7 +63,8 @@ load_info_destroy (LoadInfo *info)
{
if (!info)
return;
g_free (info->path);
if (info->path)
g_free (info->path);
if (info->i != -1)
close (info->i);
if (info->tiles != NULL)
......
......@@ -106,7 +106,8 @@ save_info_destroy (SaveInfo *info)
{
if (!info)
return;
g_free (info->path);
if (info->path)
g_free (info->path);
if (info->o != -1)
close (info->o);
if (info->tiles != NULL)
......
......@@ -211,7 +211,8 @@ gegl_buffer_set_property (GObject *gobject,
break;
case PROP_PATH:
g_free (buffer->path);
if (buffer->path)
g_free (buffer->path);
buffer->path = g_value_dup_string (value);
break;
......@@ -263,7 +264,8 @@ gegl_buffer_set_property (GObject *gobject,
break;
case PROP_BACKEND:
g_clear_object (&buffer->backend);
if (buffer->backend)
g_object_unref (buffer->backend);
buffer->backend = g_value_dup_object (value);
break;
......@@ -394,7 +396,11 @@ gegl_buffer_dispose (GObject *object)
_gegl_buffer_drop_hot_tile (buffer);
g_clear_object (&buffer->backend);
if (buffer->backend)
{
g_object_unref (buffer->backend);
buffer->backend = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
......@@ -514,7 +520,8 @@ gegl_buffer_constructor (GType type,
buffer->tile_width = gegl_tile_backend_get_tile_width (backend);
buffer->tile_height = gegl_tile_backend_get_tile_height (backend);
g_free (buffer->path);
if (buffer->path)
g_free (buffer->path);
if (GEGL_IS_TILE_BACKEND_FILE (backend))
g_object_get (backend, "path", &buffer->path, NULL);
......
......@@ -311,7 +311,8 @@ set_property (GObject *object,
break;
case PROP_TYPE:
g_free (self->type);
if (self->type)
g_free (self->type);
self->type = g_value_dup_string (value);
break;
......
......@@ -509,7 +509,8 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
if (buffer->sampler)
{
g_clear_object (&buffer->sampler);
g_object_unref (buffer->sampler);
buffer->sampler = NULL;
buffer->sampler_type = 0;
}
......@@ -558,7 +559,11 @@ gegl_buffer_sample_cleanup (GeglBuffer *buffer)
if (threaded)
g_mutex_lock (&gegl_buffer_sampler_mutex);
g_clear_object (&buffer->sampler);
if (buffer->sampler)
{
g_object_unref (buffer->sampler);
buffer->sampler = NULL;
}
if (threaded)
g_mutex_unlock (&gegl_buffer_sampler_mutex);
......
......@@ -879,7 +879,8 @@ gegl_tile_backend_file_set_property (GObject *object,
switch (property_id)
{
case PROP_PATH:
g_free (self->path);
if (self->path)
g_free (self->path);
self->path = g_value_dup_string (value);
break;
......@@ -970,8 +971,11 @@ gegl_tile_backend_file_finalize (GObject *object)
g_free (self->path);
}
g_clear_object (&self->monitor);
g_clear_object (&self->file);
if (self->monitor)
g_object_unref (self->monitor);
if (self->file)
g_object_unref (self->file);
g_cond_clear (&self->cond);
......
......@@ -49,7 +49,11 @@ gegl_tile_handler_dispose (GObject *object)
{
GeglTileHandler *handler = GEGL_TILE_HANDLER (object);
g_clear_object (&handler->source);
if (handler->source)
{
g_object_unref (handler->source);
handler->source = NULL;
}
G_OBJECT_CLASS (gegl_tile_handler_parent_class)->dispose (object);
}
......@@ -141,7 +145,16 @@ void
gegl_tile_handler_set_source (GeglTileHandler *handler,
GeglTileSource *source)
{
g_set_object (&handler->source, source);
if (source != handler->source)
{
if (handler->source)
g_object_unref (handler->source);
handler->source = source;
if (handler->source)
g_object_ref (handler->source);
}
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment