[PATCH 09/12] qemuMonitorJSONGetCPUDefinitions: Avoid double lookup of object

Peter Krempa pkrempa at redhat.com
Thu Dec 1 16:31:13 UTC 2022


Using 'virJSONValueObjectHasKey' when we want to access the value
afterwards is wasteful. Fetch the JSON value right away.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 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.38.1



More information about the libvir-list mailing list