From 77c07386e6deef9c5f3ef5f97d605bd20a5acbd0 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 5 Jan 2014 19:01:59 +0100 Subject: [PATCH] dboxinfo: avoid unnecessary 64bit math The kernel uses 'unsigned long' for those values anyway, so there is no need for 'long long' in userspace. --- src/gui/dboxinfo.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/gui/dboxinfo.cpp b/src/gui/dboxinfo.cpp index 187a2738e..a5122086f 100644 --- a/src/gui/dboxinfo.cpp +++ b/src/gui/dboxinfo.cpp @@ -230,15 +230,14 @@ void CDBoxInfoWidget::paint() #define MEMINFO_RAM 0 #define MEMINFO_SWAP 1 #define MEMINFO_ROWS 2 - unsigned long long memstat[MEMINFO_ROWS][MEMINFO_COLUMNS] = { { 0, 0, 0 }, { 0, 0, 0 } }; // total, used, free + unsigned long memstat[MEMINFO_ROWS][MEMINFO_COLUMNS] = { { 0, 0, 0 }, { 0, 0, 0 } }; // total, used, free const char *memtype[MEMINFO_ROWS] = { "RAM", "Swap" }; FILE *procmeminfo = fopen("/proc/meminfo", "r"); if (procmeminfo) { char buf[80], a[80]; - long long unsigned v; + unsigned long v; while (fgets(buf, sizeof(buf), procmeminfo)) { - if (2 == sscanf(buf, "%[^:]: %llu", a, &v)) { - v <<= 10; + if (2 == sscanf(buf, "%[^:]: %lu", a, &v)) { if (!strcasecmp(a, "MemTotal")) memstat[MEMINFO_RAM][MEMINFO_TOTAL] += v; else if (!strcasecmp(a, "MemFree")) @@ -468,13 +467,13 @@ void CDBoxInfoWidget::paint() tmp = memtype[row]; break; case 1: - tmp = bytes2string(memstat[row][MEMINFO_TOTAL]); + tmp = bytes2string(memstat[row][MEMINFO_TOTAL] << 10); break; case 2: - tmp = bytes2string(memstat[row][MEMINFO_USED]); + tmp = bytes2string(memstat[row][MEMINFO_USED] << 10); break; case 3: - tmp = bytes2string(memstat[row][MEMINFO_FREE]); + tmp = bytes2string(memstat[row][MEMINFO_FREE] << 10); break; case 4: tmp = to_string(memstat[row][MEMINFO_TOTAL] ? (memstat[row][MEMINFO_USED] * 100) / memstat[row][MEMINFO_TOTAL] : 0) + "%";