From: Jim Warner Date: Fri, 7 Oct 2016 07:22:22 +0000 (-0500) Subject: top: make that 'forest view' just a tad more efficient X-Git-Tag: v4.0.0~760 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3ec7f003274723e9d0bb8847d88f9d88c90959a;p=procps-ng top: make that 'forest view' just a tad more efficient It makes no sense to begin our tracked nested level at '1' then later require a '1' to be subtracted from the level as artwork and indentation is added for display. By beginning such tracked levels at zero, we can avoid the need to adjust it & use it directly in a snprintf. Signed-off-by: Jim Warner --- diff --git a/top/top.c b/top/top.c index 2cc12fbd..e282e2d3 100644 --- a/top/top.c +++ b/top/top.c @@ -4486,7 +4486,7 @@ static void forest_begin (WIN_t *q) { #endif for (i = 0; i < PIDSmaxt; i++) // avoid any hidepid distortions if (!rLevel) // identify real or pretend trees - forest_adds(i, 1); // add as parent plus its children + forest_adds(i, 0); // add as parent plus its children } memcpy(Seed_ppt, Tree_ppt, sizeof(void*) * PIDSmaxt); #undef rLevel @@ -4507,9 +4507,9 @@ static inline const char *forest_colour (const WIN_t *q, struct pids_stack *p) { #endif const char *which = (CHKw(q, Show_CMDLIN)) ? rSv(eu_CMDLINE) : rSv(EU_CMD); - if (!CHKw(q, Show_FOREST) || 1 == rLevel) return which; + if (!CHKw(q, Show_FOREST) || !rLevel) return which; if (rLevel > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which); - else snprintf(buf, sizeof(buf), "%*s%s", 4 * (rLevel - 1), " `- ", which); + else snprintf(buf, sizeof(buf), "%*s%s", (4 * rLevel), " `- ", which); return buf; #undef rSv #undef rLevel