[PATCH 19/32] libxml: eliminate extra copy of string

Laine Stump posted 32 patches 5 years, 7 months ago
[PATCH 19/32] libxml: eliminate extra copy of string
Posted by Laine Stump 5 years, 7 months ago
libxlMakeNic was calling g_strdup(virBufferCurrentContent(&buf)) to
make a copy of the buffer contents, and then later freeing the buffer
without ever using it again. Instead of this extra strdup, just
transfer ownership of the virBuffer's string with
virBufferContentAndReset(), and be done with it.

Signed-off-by: Laine Stump <laine@redhat.com>
---
 src/libxl/libxl_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 124e08d598..fe8ad4a3cb 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1335,7 +1335,7 @@ libxlMakeNic(virDomainDefPtr def,
                     }
                 }
             }
-            x_nic->bridge = g_strdup(virBufferCurrentContent(&buf));
+            x_nic->bridge = virBufferContentAndReset(&buf);
             G_GNUC_FALLTHROUGH;
         case VIR_DOMAIN_NET_TYPE_ETHERNET:
             x_nic->script = g_strdup(script);
-- 
2.25.4

Re: [PATCH 19/32] libxml: eliminate extra copy of string
Posted by Ján Tomko 5 years, 7 months ago
On a Sunday in 2020, Laine Stump wrote:
>libxlMakeNic was calling g_strdup(virBufferCurrentContent(&buf)) to
>make a copy of the buffer contents, and then later freeing the buffer
>without ever using it again. Instead of this extra strdup, just
>transfer ownership of the virBuffer's string with
>virBufferContentAndReset(), and be done with it.
>
>Signed-off-by: Laine Stump <laine@redhat.com>
>---
> src/libxl/libxl_conf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Re: [PATCH 19/32] libxml: eliminate extra copy of string
Posted by Ján Tomko 5 years, 7 months ago
Also, s/libxml/libxl/ in the summary

On a Sunday in 2020, Laine Stump wrote:
>libxlMakeNic was calling g_strdup(virBufferCurrentContent(&buf)) to
>make a copy of the buffer contents, and then later freeing the buffer
>without ever using it again. Instead of this extra strdup, just
>transfer ownership of the virBuffer's string with
>virBufferContentAndReset(), and be done with it.
>
>Signed-off-by: Laine Stump <laine@redhat.com>
>---
> src/libxl/libxl_conf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>

Jano