On 08/27/10 08:38, Alexander Larsson wrote:
On Fri, 2010-08-27 at 00:09 +0200, Gerd Hoffmann wrote:

+    red->data_size = qxl->data_size;
+    size = red_get_data_chunks_ptr(slots, group_id,
+                                   get_memslot_id(slots, addr),
+&chunks,&qxl->chunk);
+    data = red_linearize_chunk(&chunks, size,&free_data);
+    red_put_data_chunks(&chunks);
+    red->data = spice_malloc(size);
+    memcpy(red->data, data, size);
+
+    if (free_data) {
+        free(data);
+    }

Ack, but this part could be more efficient. In the n_chunks>  1 case the
red_linearize_chunk part will already malloc and copy the data so we
don't need to do it then.

Right.  Incremental patch attached.

We should have a linearlize_chunks variant
that always copies and use that.

Not worth the trouble for that single use case I think.

cheers,
  Gerd
From 36a81133807e057e065c5f42383239e2f078312c Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Fri, 27 Aug 2010 08:43:44 +0200
Subject: [PATCH] red_get_cursor: avoid extra copy


Signed-off-by: Gerd Hoffmann <[email protected]>
---
 server/red_parse_qxl.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/server/red_parse_qxl.c b/server/red_parse_qxl.c
index 6fa6ac5..e6e700b 100644
--- a/server/red_parse_qxl.c
+++ b/server/red_parse_qxl.c
@@ -1009,11 +1009,11 @@ static void red_get_cursor(RedMemSlotInfo *slots, int 
group_id,
                                    &chunks, &qxl->chunk);
     data = red_linearize_chunk(&chunks, size, &free_data);
     red_put_data_chunks(&chunks);
-    red->data = spice_malloc(size);
-    memcpy(red->data, data, size);
-
     if (free_data) {
-        free(data);
+        red->data = data;
+    } else {
+        red->data = spice_malloc(size);
+        memcpy(red->data, data, size);
     }
 }
 
-- 
1.7.1

_______________________________________________
Spice-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/spice-devel

Reply via email to