diff options
author | Denis Lisov <dennis.lissov@gmail.com> | 2021-12-16 19:29:18 +0300 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2022-02-13 19:50:16 +0100 |
commit | fa3e0d06c2ab48c91b1a1e3c5991fefabee870ea (patch) | |
tree | b554176a8b4949552b3a3d15f92d8c311ac5536d /ProcessList.c | |
parent | 82dce5cf8e241a46d4c9eae23423c63c5d1f17d2 (diff) |
ProcessList_buildTree: produce sorted tree
ProcessList_buildTree does not need any particular sort order for
children of the same process or roots. Switching these to the sort order
configured by the user produces sorted tree automatically, making repeat
sort unnecessary.
Diffstat (limited to 'ProcessList.c')
-rw-r--r-- | ProcessList.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ProcessList.c b/ProcessList.c index c7da84dc..c9b15ff8 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -404,7 +404,7 @@ static int ProcessList_treeProcessCompare(const void* v1, const void* v2) { return SPACESHIP_NUMBER(p1->tree_left, p2->tree_left); } -static int compareProcessByKnownParentThenPID(const void* v1, const void* v2) { +static int compareProcessByKnownParentThenNatural(const void* v1, const void* v2) { const Process* p1 = (const Process*)v1; const Process* p2 = (const Process*)v2; @@ -416,7 +416,7 @@ static int compareProcessByKnownParentThenPID(const void* v1, const void* v2) { if (result != 0) return result; - return SPACESHIP_NUMBER(p1->pid, p2->pid); + return Process_compare(v1, v2); } // Builds a sorted tree from scratch, without relying on previously gathered information @@ -449,7 +449,7 @@ static void ProcessList_buildTree(ProcessList* this) { } // Sort by known parent PID (roots first), then PID - Vector_quickSortCustomCompare(this->processes, compareProcessByKnownParentThenPID); + Vector_quickSortCustomCompare(this->processes, compareProcessByKnownParentThenNatural); // Find all processes whose parent is not visible for (int i = 0; i < vsize; i++) { @@ -470,14 +470,16 @@ static void ProcessList_buildTree(ProcessList* this) { } } + this->needsSort = false; + // Check consistency of the built structures assert(Vector_size(this->displayList) == vsize); (void)vsize; } void ProcessList_updateDisplayList(ProcessList* this) { if (this->settings->ss->treeView) { - ProcessList_updateTreeSet(this); - Vector_quickSortCustomCompare(this->displayList, ProcessList_treeProcessCompare); + if (this->needsSort) + ProcessList_buildTree(this); } else { if (this->needsSort) Vector_insertionSort(this->processes); |