summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2016-03-19 10:20:55 +0800
committerExplorer09 <explorer09@gmail.com>2016-03-22 14:52:31 +0800
commit7b3c8bc77a0ff599d683dd4d26a5da128ac837ab (patch)
treea9ecae286cdb36a3a1b192229713fab37c4c2290 /Meter.c
parent3a4c0fa2d60e2354bad25f74fc064c9abf658c48 (diff)
BarMeterMode_draw minor code improvement
Removed a loop that sets the bar[] buffer with spaces and merged that task to the snprintf() call just below. No need for the barOffset variable. Display behavior is unchanged. Size comparision (when compiled on Ubuntu 14.04 64-bit): $ size htop.old htop.new text data bss dec hex filename 137312 15112 3776 156200 26228 htop.old 137216 15112 3776 156104 261c8 htop.new
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/Meter.c b/Meter.c
index 321fd28b..039c00b8 100644
--- a/Meter.c
+++ b/Meter.c
@@ -287,11 +287,8 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
char bar[w + 1];
int blockSizes[10];
- for (int i = 0; i < w; i++)
- bar[i] = ' ';
- const size_t barOffset = w - MIN((int)strlen(buffer), w);
- snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
+ snprintf(bar, w + 1, "%*s", w, buffer);
// First draw in the bar[] buffer...
int offset = 0;

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