summaryrefslogtreecommitdiffstats
path: root/MemoryMeter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-07-29 16:24:12 +0800
committerBenBE <BenBE@geshi.org>2023-08-18 12:52:28 +0200
commitb416433fbe7ccf935ad4e268396aa423143c2318 (patch)
tree55a38c76f4f0091ed6b06d7369706bd2f1f6f61e /MemoryMeter.c
parentc6fd64fce8502a4e557711abe9fee394763ac52c (diff)
Replace isnan() with better comparisons (isgreater(), etc.)
The standard isnan() function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makes isnan() more expensive than (x != x) expression unless the compiler flag '-fno-signaling-nans' is given. Introduce functions isNaN(), isNonnegative(), isPositive(), sumPositiveValues() and compareRealNumbers(), and replace isnan() in htop's codebase with the new functions. These functions utilize isgreater() and isgreaterequal() comparisons, which do not throw FP exceptions on "quiet" NaNs, which htop uses extensively. With isnan() removed, there is no need to suppress the warning '-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'MemoryMeter.c')
-rw-r--r--MemoryMeter.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/MemoryMeter.c b/MemoryMeter.c
index 28c0be27..c7d99f88 100644
--- a/MemoryMeter.c
+++ b/MemoryMeter.c
@@ -11,6 +11,7 @@ in the source distribution for its full text.
#include <stddef.h>
#include "CRT.h"
+#include "Macros.h"
#include "Object.h"
#include "Platform.h"
#include "RichString.h"
@@ -42,9 +43,8 @@ static void MemoryMeter_updateValues(Meter* this) {
/* we actually want to show "used + compressed" */
double used = this->values[MEMORY_METER_USED];
- if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
+ if (isPositive(this->values[MEMORY_METER_COMPRESSED]))
used += this->values[MEMORY_METER_COMPRESSED];
- }
written = Meter_humanUnit(buffer, used, size);
METER_BUFFER_CHECK(buffer, size, written);
@@ -71,14 +71,14 @@ static void MemoryMeter_display(const Object* cast, RichString* out) {
RichString_appendAscii(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer);
/* shared memory is not supported on all platforms */
- if (!isnan(this->values[MEMORY_METER_SHARED])) {
+ if (isNonnegative(this->values[MEMORY_METER_SHARED])) {
Meter_humanUnit(buffer, this->values[MEMORY_METER_SHARED], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " shared:");
RichString_appendAscii(out, CRT_colors[MEMORY_SHARED], buffer);
}
/* compressed memory is not supported on all platforms */
- if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
+ if (isNonnegative(this->values[MEMORY_METER_COMPRESSED])) {
Meter_humanUnit(buffer, this->values[MEMORY_METER_COMPRESSED], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " compressed:");
RichString_appendAscii(out, CRT_colors[MEMORY_COMPRESSED], buffer);
@@ -89,7 +89,7 @@ static void MemoryMeter_display(const Object* cast, RichString* out) {
RichString_appendAscii(out, CRT_colors[MEMORY_CACHE], buffer);
/* available memory is not supported on all platforms */
- if (!isnan(this->values[MEMORY_METER_AVAILABLE])) {
+ if (isNonnegative(this->values[MEMORY_METER_AVAILABLE])) {
Meter_humanUnit(buffer, this->values[MEMORY_METER_AVAILABLE], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " available:");
RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);

© 2014-2024 Faster IT GmbH | imprint | privacy policy