virQEMUBuildDriveCommandlineFromJSON: Open-code in callers

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-03-24 14:00:07 +01:00
parent 424dc5d2d2
commit 803d3f2ca0
4 changed files with 7 additions and 22 deletions

View File

@ -3119,7 +3119,6 @@ virQEMUBuildCommandLineJSON;
virQEMUBuildCommandLineJSONArrayBitmap;
virQEMUBuildCommandLineJSONArrayNumbered;
virQEMUBuildCommandLineJSONArrayObjectsStr;
virQEMUBuildDriveCommandlineFromJSON;
# util/virrandom.h

View File

@ -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);
}

View File

@ -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

View File

@ -48,6 +48,4 @@ int virQEMUBuildCommandLineJSON(virJSONValue *value,
const char *skipKey,
virQEMUBuildCommandLineJSONArrayFormatFunc array);
char *virQEMUBuildDriveCommandlineFromJSON(virJSONValue *src);
void virQEMUBuildBufferEscapeComma(virBuffer *buf, const char *str);