From: Peter Krempa Date: Thu, 1 Dec 2022 15:13:41 +0000 (+0100) Subject: qemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object X-Git-Tag: v9.0.0-rc1~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b3bc1cb2cb05c636046dc90b9072d4acf2c2b85;p=thirdparty%2Flibvirt.git qemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object Using 'virJSONValueObjectHasKey' when we want to access the value afterwards is wasteful. Fetch the JSON value right away. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index cbd1eb6eec..1deb755130 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4842,6 +4842,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitor *mon, const char *tmp; qemuMonitorCPUDefInfo *cpu = defs->cpus + i; virJSONValue *feat; + virJSONValue *deprecated; if (!(tmp = virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -4865,8 +4866,8 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitor *mon, } } - if (virJSONValueObjectHasKey(child, "deprecated") && - virJSONValueObjectGetBoolean(child, "deprecated", &cpu->deprecated) < 0) + if ((deprecated = virJSONValueObjectGet(child, "deprecated")) && + virJSONValueGetBoolean(deprecated, &cpu->deprecated) < 0) return -1; }