提交 ac21141c 编写于 作者: P Peter Krempa

qemu: monitor: Avoid unnecessary copies of command string

Use virJSONValueToBuffer so that we can append the command terminator
string without copying of the string again. Also avoid a 'strlen' as we
can query the buffer use size.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NLaine Stump <laine@laine.org>
上级 d8306dce
......@@ -277,7 +277,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon,
{
int ret = -1;
qemuMonitorMessage msg;
char *cmdstr = NULL;
VIR_AUTOCLEAN(virBuffer) cmdbuf = VIR_BUFFER_INITIALIZER;
char *id = NULL;
*reply = NULL;
......@@ -294,11 +294,15 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon,
}
}
if (!(cmdstr = virJSONValueToString(cmd, false)))
if (virJSONValueToBuffer(cmd, &cmdbuf, false) < 0)
goto cleanup;
if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0)
virBufferAddLit(&cmdbuf, "\r\n");
if (virBufferCheckError(&cmdbuf) < 0)
goto cleanup;
msg.txLength = strlen(msg.txBuffer);
msg.txLength = virBufferUse(&cmdbuf);
msg.txBuffer = virBufferContentAndReset(&cmdbuf);
msg.txFD = scm_fd;
ret = qemuMonitorSend(mon, &msg);
......@@ -315,7 +319,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon,
cleanup:
VIR_FREE(id);
VIR_FREE(cmdstr);
VIR_FREE(msg.txBuffer);
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册