qemu-devel
[Top][All Lists]
Advanced

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

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


From: Peter Lieven
Subject: Re: [Qemu-devel] [RfC PATCH 06/10] io: add qio_buffer_move
Date: Fri, 25 Sep 2015 11:57:04 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

Am 24.09.2015 um 10:42 schrieb Gerd Hoffmann:
> 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;
> +}

Reviewed-by: Peter Lieven <address@hidden>



reply via email to

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