From b3b7a35050e29317fa66be4535aeaf83acbdc946 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 21 Aug 2018 00:00:00 -0500 Subject: [PATCH] top: a tweak to the forest view collapsed code (again) From the outset, top has tried to provide some minimal garbage collection in support of forest view collapse. For example, with every 'v' keystroke, a check is made of the currently targeted pids. If all were negative, which means expanded, that Hide_pid array was emptied. Recently, yet another efficiency was added wherein the continuing scan for a targeted pid was terminated when a match was found. But, one more inefficiency existed. When a task which was subject to collapse under forest view mode has disappeared (ended), repeatedly scanning for such a pid with each iteration makes little sense. So this commit will negate such targeted pids and thus avoid scanning every current task looking for a match. Then, if 'v' is ever stuck at some point in the future there will be a chance to empty that Hide_pid[] array. [ hopefully this will be a final tweak of the forest ] [ view collapse stuff, but cross your fingers anyway ] Signed-off-by: Jim Warner --- top/top.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/top/top.c b/top/top.c index 4146ddb7..30a2fc85 100644 --- a/top/top.c +++ b/top/top.c @@ -4805,12 +4805,17 @@ static void forest_create (WIN_t *q) { #endif children = 1; } - // children found (and collapsed), so mark that puppy + /* if any children found (and collapsed), mark the parent + ( when children aren't found we won't negate the pid ) + ( to prevent a future scan since who's to say such a ) + ( task won't fork one or more children in the future ) */ if (children) Tree_ppt[parent]->pad_2 = 'x'; - // this will force a check of the next Hide_pid, if any - j = Frame_maxtask; + // this will force a check of the next Hide_pid[], if any + j = Frame_maxtask + 1; } } + // if target task disappeared (ended), prevent further scanning + if (j == Frame_maxtask) Hide_pid[i] = -Hide_pid[i]; } } }