qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RfC PATCH 06/10] io: add qio_buffer_move


From: Gerd Hoffmann
Subject: [Qemu-devel] [RfC PATCH 06/10] io: add qio_buffer_move
Date: Thu, 24 Sep 2015 10:42:04 +0200

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 include/io/buffer.h | 10 ++++++++++
 io/buffer.c         | 16 ++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/io/buffer.h b/include/io/buffer.h
index 1dddc73..5676aff 100644
--- a/include/io/buffer.h
+++ b/include/io/buffer.h
@@ -137,4 +137,14 @@ gboolean qio_buffer_empty(QIOBuffer *buffer);
  */
 void qio_buffer_move_empty(QIOBuffer *to, QIOBuffer *from);
 
+/**
+ * qio_buffer_move:
+ * @to: destination buffer object
+ * @from: source buffer object
+ *
+ * Moves buffer, copying data (unless 'to' buffer happens to be empty).
+ * 'from' buffer is empty and zero-sized on return.
+ */
+void qio_buffer_move(QIOBuffer *to, QIOBuffer *from);
+
 #endif /* QIO_BUFFER_H__ */
diff --git a/io/buffer.c b/io/buffer.c
index 09ca321..96077d3 100644
--- a/io/buffer.c
+++ b/io/buffer.c
@@ -91,3 +91,19 @@ void qio_buffer_move_empty(QIOBuffer *to, QIOBuffer *from)
     from->capacity = 0;
     from->buffer = NULL;
 }
+
+void qio_buffer_move(QIOBuffer *to, QIOBuffer *from)
+{
+    if (to->offset == 0) {
+        qio_buffer_move_empty(to, from);
+        return;
+    }
+
+    qio_buffer_reserve(to, from->offset);
+    qio_buffer_append(to, from->buffer, from->offset);
+
+    g_free(from->buffer);
+    from->offset = 0;
+    from->capacity = 0;
+    from->buffer = NULL;
+}
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]