]> granicus.if.org Git - procps-ng/commitdiff
top: make the 'cpu_tics' function a tad more efficient
authorJim Warner <james.warner@comcast.net>
Wed, 8 Jul 2020 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 20 Jul 2020 06:12:00 +0000 (16:12 +1000)
This patch eliminates one variable which resulted in a
corresponding elimination of three 'mov' instructions.

[ that was 6 bytes per 'mov' for a total of 18 bytes ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 3dc55a6b946880af61503405f3d81cbac4ed04b5..12eddfd7ea2e4519231dd7639e1ea0ec4b3e7bc3 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -5768,7 +5768,6 @@ static int cpu_tics (CPU_t *cpu, const char *pfx, int nobuf) {
    //    user    syst    nice    idle    wait    hirg    sirq    steal
    SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme, tz;
    float scale;
-   int n;
 
    u_frme = TRIMz(cpu->cur.u - cpu->sav.u);
    s_frme = TRIMz(cpu->cur.s - cpu->sav.s);
@@ -5810,16 +5809,15 @@ static int cpu_tics (CPU_t *cpu, const char *pfx, int nobuf) {
       snprintf(syst, sizeof(syst), gtab[ix].syst, (int)((pct_syst * Graph_adj) + .4), gtab[ix].type);
 #endif
       snprintf(dual, sizeof(dual), "%s%s", user, syst);
-      n = cpu_prt(fmtmk("%s ~3%#5.1f~2/%-#5.1f~3 %3.0f[~1%-*s]~1"
+      return cpu_prt(fmtmk("%s ~3%#5.1f~2/%-#5.1f~3 %3.0f[~1%-*s]~1"
          , pfx, pct_user, pct_syst, pct_user + pct_syst, Graph_len +4, dual), nobuf);
    } else {
-      n = cpu_prt(fmtmk(Cpu_States_fmts, pfx
+      return cpu_prt(fmtmk(Cpu_States_fmts, pfx
          , (float)u_frme * scale, (float)s_frme * scale
          , (float)n_frme * scale, (float)i_frme * scale
          , (float)w_frme * scale, (float)x_frme * scale
          , (float)y_frme * scale, (float)z_frme * scale), nobuf);
    }
-   return n;
  #undef TRIMz
 } // end: cpu_tics