]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Simplify virNodeCountThreadSiblings
authorJán Tomko <jtomko@redhat.com>
Tue, 2 Jun 2015 12:29:54 +0000 (14:29 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 2 Jun 2015 14:13:14 +0000 (16:13 +0200)
Use a for loop instead of while.

Do not opencode c_isxdigit and virHexToBin.

src/nodeinfo.c

index 9db32337ba1af5fb03a7ef374d4d7db9d396ee90..2fafe2d567c203a301fc700db27c44f292d9818b 100644 (file)
@@ -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: