diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-04-14 20:47:42 +0200 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2021-04-26 17:51:45 +0200 |
commit | 436808ff99d7b7e6f5d6e8f3127d9d03f6295f98 (patch) | |
tree | 46610957022066f7da0170c1edcc5991435d5400 /NetworkIOMeter.c | |
parent | 099dab88be5a7a1c9207e7bc7116618b7108f851 (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 'NetworkIOMeter.c')
-rw-r--r-- | NetworkIOMeter.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/NetworkIOMeter.c b/NetworkIOMeter.c index 84fc12db..353521ad 100644 --- a/NetworkIOMeter.c +++ b/NetworkIOMeter.c @@ -103,6 +103,7 @@ static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* o } char buffer[64]; + int len; RichString_writeAscii(out, CRT_colors[METER_TEXT], "rx: "); Meter_humanUnit(buffer, cached_rxb_diff, sizeof(buffer)); @@ -114,8 +115,8 @@ static void NetworkIOMeter_display(ATTR_UNUSED const Object* cast, RichString* o RichString_appendAscii(out, CRT_colors[METER_VALUE_IOWRITE], buffer); RichString_appendAscii(out, CRT_colors[METER_VALUE_IOWRITE], "iB/s"); - xSnprintf(buffer, sizeof(buffer), " (%u/%u packets) ", cached_rxp_diff, cached_txp_diff); - RichString_appendAscii(out, CRT_colors[METER_TEXT], buffer); + len = xSnprintf(buffer, sizeof(buffer), " (%u/%u packets) ", cached_rxp_diff, cached_txp_diff); + RichString_appendnAscii(out, CRT_colors[METER_TEXT], buffer, len); } const MeterClass NetworkIOMeter_class = { |