[PATCH 4/4] hyverv: hypervCreateEmbeddedParam: Rework items counting

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

 



It's not necessarily clear, why we need to create the hash table
as big as number of fields we want to store, but nevertheless,
the code can be written a bit better. The @count should be type
of size_t and could be used directly in the loop that counts the
fields.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/hyperv/hyperv_wmi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 489bb03a9b..8bebf02a50 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -317,10 +317,9 @@ virHashTablePtr
 hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
 {
     size_t i;
-    int count = 0;
+    size_t count;
     g_autoptr(virHashTable) table = NULL;
     XmlSerializerInfo *typeinfo = NULL;
-    XmlSerializerInfo *item = NULL;
     hypervWmiClassInfoPtr classInfo = NULL;
 
     /* Get the typeinfo out of the class info list */
@@ -330,15 +329,15 @@ hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr info)
     typeinfo = classInfo->serializerInfo;
 
     /* loop through the items to find out how many fields there are */
-    for (i = 0; typeinfo[i].name != NULL; i++) {}
-    count = i;
+    for (count = 0; typeinfo[count].name != NULL; count++)
+        ;
 
     table = virHashCreate(count, NULL);
     if (table == NULL)
         return NULL;
 
     for (i = 0; typeinfo[i].name != NULL; i++) {
-        item = &typeinfo[i];
+        XmlSerializerInfo *item = &typeinfo[i];
 
         if (virHashAddEntry(table, item->name, NULL) < 0)
             return NULL;
-- 
2.26.2




[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]

  Powered by Linux