[PATCH 3/2] qemu: cap: Refactor access to array in virQEMUCapsProbeQMPMachineTypes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use a temporary pointer rather than always recalculating the index in a
very verbose way.
---
 src/qemu/qemu_capabilities.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 23d4a65..c612960 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2473,6 +2473,7 @@ static int
 virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
                                 qemuMonitorPtr mon)
 {
+    struct virQEMUCapsMachineType *mach;
     qemuMonitorMachineInfoPtr *machines = NULL;
     int nmachines = 0;
     int ret = -1;
@@ -2488,16 +2489,17 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
     for (i = 0; i < nmachines; i++) {
         if (STREQ(machines[i]->name, "none"))
             continue;
-        qemuCaps->nmachineTypes++;
-        if (VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes -1].alias,
-                       machines[i]->alias) < 0 ||
-            VIR_STRDUP(qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1].name,
-                       machines[i]->name) < 0)
+
+        mach = &(qemuCaps->machineTypes[qemuCaps->nmachineTypes++]);
+
+        if (VIR_STRDUP(mach->alias, machines[i]->alias) < 0 ||
+            VIR_STRDUP(mach->name, machines[i]->name) < 0)
             goto cleanup;
+
+        mach->maxCpus = machines[i]->maxCpus;
+
         if (machines[i]->isDefault)
             defIdx = qemuCaps->nmachineTypes - 1;
-        qemuCaps->machineTypes[qemuCaps->nmachineTypes - 1].maxCpus =
-            machines[i]->maxCpus;
     }

     if (defIdx)
-- 
2.9.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]