[gegl] buffer: do not do memcpy for uncloning empty tiles
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: do not do memcpy for uncloning empty tiles
- Date: Mon, 8 Apr 2013 21:15:44 +0000 (UTC)
commit 4e3c942a55da9ded6488de399e8a06fabdc24cb4
Author: Øyvind Kolås <pippin gimp org>
Date: Mon Apr 8 23:15:10 2013 +0200
buffer: do not do memcpy for uncloning empty tiles
gegl/buffer/gegl-buffer-private.h | 1 +
gegl/buffer/gegl-tile-handler-empty.c | 1 +
gegl/buffer/gegl-tile.c | 20 ++++++++++++++++----
gegl/gegl-utils.c | 9 +++++++++
gegl/gegl-utils.h | 1 +
5 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index b41516d..5a72a99 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -169,6 +169,7 @@ struct _GeglTile
gchar lock; /* number of times the tile is write locked
* should in theory just have the values 0/1
*/
+ gint is_zero_tile:1;
/* the shared list is a doubly linked circular list */
GeglTile *next_shared;
diff --git a/gegl/buffer/gegl-tile-handler-empty.c b/gegl/buffer/gegl-tile-handler-empty.c
index c5d2614..6b0f9d7 100644
--- a/gegl/buffer/gegl-tile-handler-empty.c
+++ b/gegl/buffer/gegl-tile-handler-empty.c
@@ -63,6 +63,7 @@ get_tile (GeglTileSource *gegl_tile_source,
gint tile_size = gegl_tile_backend_get_tile_size (empty->backend);
empty->tile = gegl_tile_new (tile_size);
memset (gegl_tile_get_data (empty->tile), 0x00, tile_size);
+ empty->tile->is_zero_tile = 1;
}
return gegl_tile_handler_dup_tile (GEGL_TILE_HANDLER (empty),
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index 1be57b7..b9c43e4 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -110,9 +110,10 @@ gegl_tile_dup (GeglTile *src)
{
GeglTile *tile = gegl_tile_new_bare ();
- tile->tile_storage = src->tile_storage;
- tile->data = src->data;
- tile->size = src->size;
+ tile->tile_storage = src->tile_storage;
+ tile->data = src->data;
+ tile->size = src->size;
+ tile->is_zero_tile = src->is_zero_tile;
tile->destroy_notify = src->destroy_notify;
tile->destroy_notify_data = src->destroy_notify_data;
@@ -165,13 +166,24 @@ gegl_tile_unclone (GeglTile *tile)
* create a local copy
*/
g_mutex_lock (&cowmutex);
- tile->data = gegl_memdup (tile->data, tile->size);
+
+ if (tile->is_zero_tile)
+ {
+ tile->data = gegl_memdup (tile->data, tile->size);
+ tile->is_zero_tile = 0;
+ }
+ else
+ {
+ tile->data = gegl_memdup (tile->data, tile->size);
+ }
tile->destroy_notify = (void*)&free_data_directly;
tile->destroy_notify_data = NULL;
tile->prev_shared->next_shared = tile->next_shared;
tile->next_shared->prev_shared = tile->prev_shared;
tile->prev_shared = tile;
tile->next_shared = tile;
+
+
g_mutex_unlock (&cowmutex);
}
}
diff --git a/gegl/gegl-utils.c b/gegl/gegl-utils.c
index 812a9e8..39f1b4b 100644
--- a/gegl/gegl-utils.c
+++ b/gegl/gegl-utils.c
@@ -18,6 +18,7 @@
#include "config.h"
+#include <string.h>
#include <glib-object.h>
#include "gegl.h"
@@ -249,6 +250,14 @@ gpointer gegl_malloc (gsize size)
return (gpointer) ret;
}
+gpointer gegl_calloc (gsize size, int n_memb);
+gpointer gegl_calloc (gsize size, int n_memb)
+{
+ gchar *ret = gegl_malloc (size * n_memb);
+ memset (ret, 0, size * n_memb);
+ return ret;
+}
+
void
gegl_free (gpointer buf);
void
diff --git a/gegl/gegl-utils.h b/gegl/gegl-utils.h
index aea6eb5..039c969 100644
--- a/gegl/gegl-utils.h
+++ b/gegl/gegl-utils.h
@@ -196,6 +196,7 @@ gpointer gegl_malloc (gsize n_bytes);
*/
void gegl_free (gpointer mem);
+gpointer gegl_calloc (gsize size, int n_memb);
#define GEGL_FLOAT_EPSILON (1e-5)
#define GEGL_FLOAT_IS_ZERO(value) (_gegl_float_epsilon_zero ((value)))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]