[gegl] buffer: don't copy/zero data when uncloning fully-damaged tile



commit 3636a2642d1668dcc635270c1cfbc4e24d349372
Author: Ell <ell_se yahoo com>
Date:   Tue Jan 1 14:21:45 2019 -0500

    buffer: don't copy/zero data when uncloning fully-damaged tile
    
    When uncloning a fully-damaged tile, allocate a new buffer for the
    tile data, but don't copy the old data over (or zero the new
    buffer, if it's an empty tile), since the existing data is
    conceptually invalid, and will be overwritten anyway.
    
    The next few commits fully damage tiles that are going to be fully
    overwritten, so that, if they have to be uncloned, we don't
    needlessly copy/zero their data.

 gegl/buffer/gegl-tile.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index bbedefd65..9fd0e8ba1 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -205,7 +205,30 @@ gegl_tile_unclone (GeglTile *tile)
       /* the tile data is shared with other tiles,
        * create a local copy
        */
-      if (tile->is_zero_tile)
+
+      if (! ~tile->damage)
+        {
+          /* if the tile is fully damaged, we only need to allocate a new
+           * buffer, but we don't have to copy the old one.
+           */
+
+          tile->is_zero_tile = FALSE;
+
+          if (g_atomic_int_dec_and_test (gegl_tile_n_clones (tile)))
+            {
+              /* someone else uncloned the tile in the meantime, and we're now
+               * the last copy; bail.
+               */
+              *gegl_tile_n_clones (tile)        = 1;
+              *gegl_tile_n_cached_clones (tile) = cached;
+
+              goto end;
+            }
+
+          tile->n_clones = gegl_malloc (INLINE_N_ELEMENTS_DATA_OFFSET +
+                                        tile->size);
+        }
+      else if (tile->is_zero_tile)
         {
           tile->is_zero_tile = FALSE;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]