Optimize the number of string copies by using the virBuffers in the callers directly. Simplest way to achieve this is to just open code the one function call 'virQEMUBuildDriveCommandlineFromJSON' was wrapping in the two callers. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/libvirt_private.syms | 1 - src/qemu/qemu_command.c | 13 +++++++------ src/util/virqemu.c | 13 ------------- src/util/virqemu.h | 2 -- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cffd3d638c..516b3692b2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3119,7 +3119,6 @@ virQEMUBuildCommandLineJSON; virQEMUBuildCommandLineJSONArrayBitmap; virQEMUBuildCommandLineJSONArrayNumbered; virQEMUBuildCommandLineJSONArrayObjectsStr; -virQEMUBuildDriveCommandlineFromJSON; # util/virrandom.h diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3c5aa94f11..19b1119e4a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1252,10 +1252,9 @@ qemuBuildDriveSourceStr(virDomainDiskDef *disk, if (qemuBuildDriveSourcePR(buf, disk) < 0) return -1; } else { - if (!(source = virQEMUBuildDriveCommandlineFromJSON(srcprops))) + if (virQEMUBuildCommandLineJSON(srcprops, buf, NULL, + virQEMUBuildCommandLineJSONArrayNumbered) < 0) return -1; - - virBufferAdd(buf, source, -1); } virBufferAddLit(buf, ","); @@ -4533,16 +4532,18 @@ static char * qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDef *dev) { g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - g_autofree char *netsource = NULL; g_autoptr(virJSONValue) srcprops = NULL; virDomainHostdevSubsysSCSI *scsisrc = &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIiSCSI *iscsisrc = &scsisrc->u.iscsi; if (!(srcprops = qemuDiskSourceGetProps(iscsisrc->src))) return NULL; - if (!(netsource = virQEMUBuildDriveCommandlineFromJSON(srcprops))) + + if (virQEMUBuildCommandLineJSON(srcprops, &buf, NULL, + virQEMUBuildCommandLineJSONArrayNumbered) < 0) return NULL; - virBufferAsprintf(&buf, "%s,if=none,format=raw", netsource); + + virBufferAddLit(&buf, ",if=none,format=raw"); return virBufferContentAndReset(&buf); } diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 8119643431..e31451dff4 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -283,19 +283,6 @@ virQEMUBuildCommandLineJSON(virJSONValue *value, } -char * -virQEMUBuildDriveCommandlineFromJSON(virJSONValue *srcdef) -{ - g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - - if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, - virQEMUBuildCommandLineJSONArrayNumbered) < 0) - return NULL; - - return virBufferContentAndReset(&buf); -} - - /** * virQEMUBuildBufferEscapeComma: * @buf: buffer to append the escaped string diff --git a/src/util/virqemu.h b/src/util/virqemu.h index 5098ed7653..472f24de53 100644 --- a/src/util/virqemu.h +++ b/src/util/virqemu.h @@ -48,6 +48,4 @@ int virQEMUBuildCommandLineJSON(virJSONValue *value, const char *skipKey, virQEMUBuildCommandLineJSONArrayFormatFunc array); -char *virQEMUBuildDriveCommandlineFromJSON(virJSONValue *src); - void virQEMUBuildBufferEscapeComma(virBuffer *buf, const char *str); -- 2.31.1