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:
parent
810082d15c
commit
4d1eb5fdb1
@ -127,4 +127,14 @@ uint8_t *buffer_end(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__ */
|
||||
|
@ -77,3 +77,17 @@ void buffer_advance(Buffer *buffer, size_t 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user