[libvirt] [PATCH 15/19] util: buffer: Reimplement virBuffer internals using glib's GString
Ján Tomko
jtomko at redhat.com
Thu Oct 24 14:59:23 UTC 2019
On Thu, Oct 24, 2019 at 03:56:33PM +0200, Peter Krempa wrote:
>GString is surprisingly similar to what libvirt was doing painstaikingly
painstakingly
Imagine a pancake, but much more convoluted.
>manually. Yet it doesn't support the automatic indentation features we
>use for XML so we rather keep those in form of virBuffer using GString
>internally.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> src/util/virbuffer.c | 205 +++++++++++++++----------------------------
> src/util/virbuffer.h | 6 +-
> 2 files changed, 71 insertions(+), 140 deletions(-)
>
>diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
>index 2256bd5de5..9306b79703 100644
>--- a/src/util/virbuffer.c
>+++ b/src/util/virbuffer.c
>+static void
>+virBufferApplyIndent(virBufferPtr buf)
>+{
>+ const char space[] = " ";
>+ size_t spacesz = sizeof(space) - 1;
/* infinity minus one */
>+ size_t toindent = virBufferGetEffectiveIndent(buf);
>
>- size = buf->use + len + 1000;
>+ if (toindent == 0)
>+ return;
>
>@@ -810,21 +737,27 @@ virBufferTrim(virBufferPtr buf, const char *str, int len)
> {
> size_t len2 = 0;
>
>- if (!buf || buf->error)
>+ if (!buf || buf->error || !buf->str)
> return;
>+
> if (!str && len < 0)
> return;
>
>- if (len > 0 && len > buf->use)
>+
>+ if (len > 0 && len > buf->str->len)
> return;
>+
> if (str) {
> len2 = strlen(str);
>- if (len2 > buf->use ||
>- memcmp(&buf->content[buf->use - len2], str, len2) != 0)
>+ if (len2 > buf->str->len ||
>+ memcmp(&buf->str->str[buf->str->len - len2], str, len2) != 0)
> return;
> }
>- buf->use -= len < 0 ? len2 : len;
>- buf->content[buf->use] = '\0';
>+
>+ if (len < 0)
>+ len = len2;
This function is odd. Maybe it would work better as two (which is - ironically -
even) separate ones. But the conversion looks good.
>+
>+ g_string_truncate(buf->str, buf->str->len - len);
> }
>
>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191024/59428d39/attachment-0001.sig>
More information about the libvir-list
mailing list