summaryrefslogtreecommitdiffstats
path: root/linux/SystemdMeter.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-04-14 20:47:42 +0200
committercgzones <cgzones@googlemail.com>2021-04-26 17:51:45 +0200
commit436808ff99d7b7e6f5d6e8f3127d9d03f6295f98 (patch)
tree46610957022066f7da0170c1edcc5991435d5400 /linux/SystemdMeter.c
parent099dab88be5a7a1c9207e7bc7116618b7108f851 (diff)
Use RichString_appendnAscii where possible
`RichString_appendnAscii()` avoids a `strlen(3)` call over ` RichString_appendAscii()`. Use the former where the length is available from a previous checked `snprintf(3)` call. Keep `RichString_appendAscii()` when passing a string literal and rely on compilers to optimize the `strlen(3)` call away.
Diffstat (limited to 'linux/SystemdMeter.c')
-rw-r--r--linux/SystemdMeter.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/linux/SystemdMeter.c b/linux/SystemdMeter.c
index a891eb11..47b86563 100644
--- a/linux/SystemdMeter.c
+++ b/linux/SystemdMeter.c
@@ -305,6 +305,7 @@ static int valueDigitColor(unsigned int value) {
static void SystemdMeter_display(ATTR_UNUSED const Object* cast, RichString* out) {
char buffer[16];
+ int len;
int color = (systemState && String_eq(systemState, "running")) ? METER_VALUE_OK : METER_VALUE_ERROR;
RichString_writeAscii(out, CRT_colors[color], systemState ? systemState : "N/A");
@@ -314,40 +315,44 @@ static void SystemdMeter_display(ATTR_UNUSED const Object* cast, RichString* out
if (nFailedUnits == INVALID_VALUE) {
buffer[0] = '?';
buffer[1] = '\0';
+ len = 1;
} else {
- xSnprintf(buffer, sizeof(buffer), "%u", nFailedUnits);
+ len = xSnprintf(buffer, sizeof(buffer), "%u", nFailedUnits);
}
- RichString_appendAscii(out, zeroDigitColor(nFailedUnits), buffer);
+ RichString_appendnAscii(out, zeroDigitColor(nFailedUnits), buffer, len);
RichString_appendAscii(out, CRT_colors[METER_TEXT], "/");
if (nNames == INVALID_VALUE) {
buffer[0] = '?';
buffer[1] = '\0';
+ len = 1;
} else {
- xSnprintf(buffer, sizeof(buffer), "%u", nNames);
+ len = xSnprintf(buffer, sizeof(buffer), "%u", nNames);
}
- RichString_appendAscii(out, valueDigitColor(nNames), buffer);
+ RichString_appendnAscii(out, valueDigitColor(nNames), buffer, len);
RichString_appendAscii(out, CRT_colors[METER_TEXT], " failed) (");
if (nJobs == INVALID_VALUE) {
buffer[0] = '?';
buffer[1] = '\0';
+ len = 1;
} else {
- xSnprintf(buffer, sizeof(buffer), "%u", nJobs);
+ len = xSnprintf(buffer, sizeof(buffer), "%u", nJobs);
}
- RichString_appendAscii(out, zeroDigitColor(nJobs), buffer);
+ RichString_appendnAscii(out, zeroDigitColor(nJobs), buffer, len);
RichString_appendAscii(out, CRT_colors[METER_TEXT], "/");
if (nInstalledJobs == INVALID_VALUE) {
buffer[0] = '?';
buffer[1] = '\0';
+ len = 1;
} else {
- xSnprintf(buffer, sizeof(buffer), "%u", nInstalledJobs);
+ len = xSnprintf(buffer, sizeof(buffer), "%u", nInstalledJobs);
}
- RichString_appendAscii(out, valueDigitColor(nInstalledJobs), buffer);
+ RichString_appendnAscii(out, valueDigitColor(nInstalledJobs), buffer, len);
RichString_appendAscii(out, CRT_colors[METER_TEXT], " jobs)");
}

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