[PATCH 2/2] Simplify virNodeCountThreadSiblings

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

 



Use a for cycle instead of while.

Do not opencode c_isxdigit and virHexToBin.
---
 src/nodeinfo.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 9db3233..2fafe2d 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -361,15 +361,9 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
     if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &str) < 0)
         goto cleanup;
 
-    i = 0;
-    while (str[i] != '\0') {
-        if (c_isdigit(str[i]))
-            ret += count_one_bits(str[i] - '0');
-        else if (str[i] >= 'A' && str[i] <= 'F')
-            ret += count_one_bits(str[i] - 'A' + 10);
-        else if (str[i] >= 'a' && str[i] <= 'f')
-            ret += count_one_bits(str[i] - 'a' + 10);
-        i++;
+    for (i = 0; str[i] != '\0'; i++) {
+        if (c_isxdigit(str[i]))
+            ret += count_one_bits(virHexToBin(str[i]));
     }
 
  cleanup:
-- 
2.3.6

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