From 18eb727fe9229e5ef729c64930ae0a196c82a33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 2 Jun 2015 14:29:54 +0200 Subject: [PATCH] Simplify virNodeCountThreadSiblings Use a for loop 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 9db32337ba..2fafe2d567 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: