buffer: add buffer_move_empty

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Peter Lieven <pl@kamp.de>
Reviewed-by: Daniel Berrange <berrange@redhat.com>
Message-id: 1446203414-4013-4-git-send-email-kraxel@redhat.com
This commit is contained in:
Gerd Hoffmann 2015-10-30 12:09:58 +01:00
parent 810082d15c
commit 4d1eb5fdb1
2 changed files with 24 additions and 0 deletions

View File

@ -127,4 +127,14 @@ uint8_t *buffer_end(Buffer *buffer);
*/ */
gboolean buffer_empty(Buffer *buffer); gboolean buffer_empty(Buffer *buffer);
/**
* buffer_move_empty:
* @to: destination buffer object
* @from: source buffer object
*
* Moves buffer, without copying data. 'to' buffer must be empty.
* 'from' buffer is empty and zero-sized on return.
*/
void buffer_move_empty(Buffer *to, Buffer *from);
#endif /* QEMU_BUFFER_H__ */ #endif /* QEMU_BUFFER_H__ */

View File

@ -77,3 +77,17 @@ void buffer_advance(Buffer *buffer, size_t len)
(buffer->offset - len)); (buffer->offset - len));
buffer->offset -= len; buffer->offset -= len;
} }
void buffer_move_empty(Buffer *to, Buffer *from)
{
assert(to->offset == 0);
g_free(to->buffer);
to->offset = from->offset;
to->capacity = from->capacity;
to->buffer = from->buffer;
from->offset = 0;
from->capacity = 0;
from->buffer = NULL;
}