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
7e6a371d8a36b250a2edddff9f5d059640b8132e
. top employs PIDS_noop at 'new' time
commit
f1bd82ff07d67dbcfa455e82678f44376cfe1a90
. <pids> relocated PIDS_noop (PIDS_noop == 0)
commit
e7585992d9c0743246247b3d6ee0041942fe07d5
Signed-off-by: Jim Warner <james.warner@comcast.net>
// establish max depth for newlib pids stack (# of result structs)
Pids_itms = alloc_c(sizeof(enum pids_item) * MAXTBL(Fieldstab));
- for (i = 0; i < MAXTBL(Fieldstab); i++)
- Pids_itms[i] = PIDS_noop;
- Pids_itms_cur = i;
+ if (PIDS_noop != 0)
+ for (i = 0; i < MAXTBL(Fieldstab); i++)
+ Pids_itms[i] = PIDS_noop;
+ Pids_itms_cur = MAXTBL(Fieldstab);
// we will identify specific items in the build_headers() function
if (procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__));