[gtk-vnc] Make handling of ZRLE encoding more efficient
- From: Daniel P. Berrange <dberrange src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-vnc] Make handling of ZRLE encoding more efficient
- Date: Mon, 16 Sep 2013 10:48:36 +0000 (UTC)
commit 851f328457507443578078eb78189af4f5e0267f
Author: Artem Rusanov <artem rusanov gmail com>
Date: Fri Sep 13 12:23:09 2013 +0100
Make handling of ZRLE encoding more efficient
Avoid memmove() on the uncompressed data buffer when dealing
with ZRLE encoding. Instead just track what offset we've read
upto.
Signed-off-by: Daniel P. Berrange <berrange redhat com>
src/vncconnection.c | 33 ++++++++++++++++++---------------
1 files changed, 18 insertions(+), 15 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 46f41f7..d476dd4 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -208,7 +208,8 @@ struct _VncConnectionPrivate
z_stream *strm;
z_stream streams[5];
- size_t uncompressed_length;
+ size_t uncompressed_offset;
+ size_t uncompressed_size;
guint8 uncompressed_buffer[4096];
size_t compressed_length;
@@ -624,19 +625,15 @@ static int vnc_connection_zread(VncConnection *conn, void *buffer, size_t size)
while (offset < size) {
/* if data is available in the uncompressed buffer, then
* copy */
- if (priv->uncompressed_length) {
- size_t len = MIN(priv->uncompressed_length,
+ if (priv->uncompressed_size - priv->uncompressed_offset) {
+ size_t len = MIN(priv->uncompressed_size - priv->uncompressed_offset,
size - offset);
memcpy(ptr + offset,
- priv->uncompressed_buffer,
+ priv->uncompressed_buffer + priv->uncompressed_offset,
len);
- priv->uncompressed_length -= len;
- if (priv->uncompressed_length)
- memmove(priv->uncompressed_buffer,
- priv->uncompressed_buffer + len,
- priv->uncompressed_length);
+ priv->uncompressed_offset += len;
offset += len;
} else {
int err;
@@ -653,7 +650,8 @@ static int vnc_connection_zread(VncConnection *conn, void *buffer, size_t size)
return -1;
}
- priv->uncompressed_length = (guint8 *)priv->strm->next_out - priv->uncompressed_buffer;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = (guint8 *)priv->strm->next_out - priv->uncompressed_buffer;
priv->compressed_length -= (guint8 *)priv->strm->next_in - priv->compressed_buffer;
priv->compressed_buffer = priv->strm->next_in;
}
@@ -2288,7 +2286,8 @@ static void vnc_connection_zrle_update(VncConnection *conn,
vnc_connection_read(conn, zlib_data, length);
/* setup subsequent calls to vnc_connection_read*() to use the compressed data */
- priv->uncompressed_length = 0;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = 0;
priv->compressed_length = length;
priv->compressed_buffer = zlib_data;
priv->strm = &priv->streams[0];
@@ -2304,7 +2303,8 @@ static void vnc_connection_zrle_update(VncConnection *conn,
}
priv->strm = NULL;
- priv->uncompressed_length = 0;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = 0;
priv->compressed_length = 0;
priv->compressed_buffer = NULL;
@@ -2568,7 +2568,8 @@ static void vnc_connection_tight_update(VncConnection *conn,
vnc_connection_read(conn, zlib_data, zlib_length);
- priv->uncompressed_length = 0;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = 0;
priv->compressed_length = zlib_length;
priv->compressed_buffer = zlib_data;
}
@@ -2592,7 +2593,8 @@ static void vnc_connection_tight_update(VncConnection *conn,
}
if (data_size >= 12) {
- priv->uncompressed_length = 0;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = 0;
priv->compressed_length = 0;
priv->compressed_buffer = NULL;
@@ -4813,7 +4815,8 @@ static void vnc_connection_close(VncConnection *conn)
priv->read_offset = priv->read_size = 0;
priv->write_offset = 0;
- priv->uncompressed_length = 0;
+ priv->uncompressed_offset = 0;
+ priv->uncompressed_size = 0;
priv->compressed_length = 0;
priv->width = priv->height = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]