From 6b3bc1cb2cb05c636046dc90b9072d4acf2c2b85 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 1 Dec 2022 16:13:41 +0100 Subject: [PATCH] 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 --- src/qemu/qemu_monitor_json.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; } -- 2.47.2