]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virresctrl: Use g_strsplit instead of virStringSplitCount
authorPeter Krempa <pkrempa@redhat.com>
Tue, 23 Mar 2021 17:06:33 +0000 (18:06 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 12 Apr 2021 13:55:10 +0000 (15:55 +0200)
In 3 of 4 instances the code didn't even need the count of the elements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virresctrl.c

index 0e765f189838dab549662582cd88b2955d0735de..f1649f967b9f39c9f74e93db8de9cb9d39f624ae 100644 (file)
@@ -697,8 +697,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
 {
     int rv = -1;
     g_autofree char *featurestr = NULL;
-    g_auto(GStrv) features = NULL;
-    size_t nfeatures = 0;
     g_autofree virResctrlInfoMongrpPtr info_monitor = NULL;
 
     info_monitor = g_new0(virResctrlInfoMongrp, 1);
@@ -748,11 +746,10 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
         return -1;
     }
 
-    features = virStringSplitCount(featurestr, "\n", 0, &nfeatures);
-    VIR_DEBUG("Resctrl supported %zd monitoring features", nfeatures);
+    info_monitor->features = g_strsplit(featurestr, "\n", 0);
+    info_monitor->nfeatures = g_strv_length(info_monitor->features);
+    VIR_DEBUG("Resctrl supported %zd monitoring features", info_monitor->nfeatures);
 
-    info_monitor->nfeatures = nfeatures;
-    info_monitor->features = g_steal_pointer(&features);
     resctrl->monitor_info = g_steal_pointer(&info_monitor);
 
     return 0;
@@ -1466,9 +1463,8 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl,
                                         char *line)
 {
     g_auto(GStrv) mbs = NULL;
+    GStrv next;
     char *tmp = NULL;
-    size_t nmbs = 0;
-    size_t i;
 
     /* For no reason there can be spaces */
     virSkipSpaces((const char **) &line);
@@ -1493,9 +1489,9 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInfoPtr resctrl,
         return 0;
     tmp++;
 
-    mbs = virStringSplitCount(tmp, ";", 0, &nmbs);
-    for (i = 0; i < nmbs; i++) {
-        if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, mbs[i]) < 0)
+    mbs = g_strsplit(tmp, ";", 0);
+    for (next = mbs; *next; next++) {
+        if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, *next) < 0)
             return -1;
     }
 
@@ -1620,11 +1616,10 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resctrl,
                               char *line)
 {
     g_auto(GStrv) caches = NULL;
+    GStrv next;
     char *tmp = NULL;
     unsigned int level = 0;
     int type = -1;
-    size_t ncaches = 0;
-    size_t i = 0;
 
     /* For no reason there can be spaces */
     virSkipSpaces((const char **) &line);
@@ -1656,12 +1651,12 @@ virResctrlAllocParseCacheLine(virResctrlInfoPtr resctrl,
         return -1;
     }
 
-    caches = virStringSplitCount(tmp, ";", 0, &ncaches);
+    caches = g_strsplit(tmp, ";", 0);
     if (!caches)
         return 0;
 
-    for (i = 0; i < ncaches; i++) {
-        if (virResctrlAllocParseProcessCache(resctrl, alloc, level, type, caches[i]) < 0)
+    for (next = caches; *next; next++) {
+        if (virResctrlAllocParseProcessCache(resctrl, alloc, level, type, *next) < 0)
             return -1;
     }
 
@@ -1675,14 +1670,13 @@ virResctrlAllocParse(virResctrlInfoPtr resctrl,
                      const char *schemata)
 {
     g_auto(GStrv) lines = NULL;
-    size_t nlines = 0;
-    size_t i = 0;
+    GStrv next;
 
-    lines = virStringSplitCount(schemata, "\n", 0, &nlines);
-    for (i = 0; i < nlines; i++) {
-        if (virResctrlAllocParseCacheLine(resctrl, alloc, lines[i]) < 0)
+    lines = g_strsplit(schemata, "\n", 0);
+    for (next = lines; *next; next++) {
+        if (virResctrlAllocParseCacheLine(resctrl, alloc, *next) < 0)
             return -1;
-        if (virResctrlAllocParseMemoryBandwidthLine(resctrl, alloc, lines[i]) < 0)
+        if (virResctrlAllocParseMemoryBandwidthLine(resctrl, alloc, *next) < 0)
             return -1;
     }