mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
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.
This commit is contained in:

committed by
cgzones

parent
099dab88be
commit
436808ff99
@ -53,12 +53,14 @@ static void PressureStallMeter_updateValues(Meter* this) {
|
||||
static void PressureStallMeter_display(const Object* cast, RichString* out) {
|
||||
const Meter* this = (const Meter*)cast;
|
||||
char buffer[20];
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[0]);
|
||||
RichString_writeAscii(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[1]);
|
||||
RichString_appendAscii(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer);
|
||||
xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[2]);
|
||||
RichString_appendAscii(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer);
|
||||
int len;
|
||||
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[0]);
|
||||
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_TEN], buffer, len);
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[1]);
|
||||
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer, len);
|
||||
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[2]);
|
||||
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer, len);
|
||||
}
|
||||
|
||||
const MeterClass PressureStallCPUSomeMeter_class = {
|
||||
|
@ -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)");
|
||||
}
|
||||
|
Reference in New Issue
Block a user