]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Dec 2022 15:13:41 +0000 (16:13 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 2 Dec 2022 15:18:37 +0000 (16:18 +0100)
Using 'virJSONValueObjectHasKey' when we want to access the value
afterwards is wasteful. Fetch the JSON value right away.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index cbd1eb6eec2dce1cffa07ecfd8211c1fa9ad592a..1deb755130c43caafd1e58b9c225ad3207fd4b31 100644 (file)
@@ -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;
     }