top: at program startup, avoid a little extra overhead

There was a time when the PROCPS_PIDS_noop represented
the highest valued enumerator. Therefore if one wished
to prime an array consisting of pids_result structures
with this specific item a loop would have been needed.

Now that this enum is the first one, with the value of
zero, we can avoid avoid such a loop with just calloc.

But just in case, we'll use an 'if' to guarantee zero.

[ and the nice thing is, since the value is known at ]
[ compile time, that 'if' test plus subordinate loop ]
[ can be discarded by the compiler as long as it's 0 ]

Reference(s):
. <pids> introduced (PIDS_noop > 0)
commit 7e6a371d8a
. top employs PIDS_noop at 'new' time
commit f1bd82ff07
. <pids> relocated PIDS_noop (PIDS_noop == 0)
commit e7585992d9

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-07-30 00:00:00 -05:00 committed by Craig Small
parent 8c624ca9dc
commit bb19ac0926

View File

@ -2821,9 +2821,10 @@ static void before (char *me) {
// establish max depth for newlib pids stack (# of result structs) // establish max depth for newlib pids stack (# of result structs)
Pids_itms = alloc_c(sizeof(enum pids_item) * MAXTBL(Fieldstab)); Pids_itms = alloc_c(sizeof(enum pids_item) * MAXTBL(Fieldstab));
for (i = 0; i < MAXTBL(Fieldstab); i++) if (PIDS_noop != 0)
Pids_itms[i] = PIDS_noop; for (i = 0; i < MAXTBL(Fieldstab); i++)
Pids_itms_cur = i; Pids_itms[i] = PIDS_noop;
Pids_itms_cur = MAXTBL(Fieldstab);
// we will identify specific items in the build_headers() function // we will identify specific items in the build_headers() function
if (procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur)) if (procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__));