summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Lisov <dennis.lissov@gmail.com>2021-12-16 19:29:18 +0300
committerBenBE <BenBE@geshi.org>2022-02-13 19:50:16 +0100
commitfa3e0d06c2ab48c91b1a1e3c5991fefabee870ea (patch)
treeb554176a8b4949552b3a3d15f92d8c311ac5536d
parent82dce5cf8e241a46d4c9eae23423c63c5d1f17d2 (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.
-rw-r--r--ProcessList.c12
-rw-r--r--ScreenManager.c8
2 files changed, 11 insertions, 9 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);
diff --git a/ScreenManager.c b/ScreenManager.c
index 396622e3..e4b04bd3 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -121,14 +121,14 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
if (*rescan) {
*oldTime = newTime;
int oldUidDigits = Process_uidDigits;
- // scan processes first - some header values are calculated there
- ProcessList_scan(pl, this->state->pauseProcessUpdate);
- // always update header, especially to avoid gaps in graph meters
- Header_updateData(this->header);
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
pl->needsSort = true;
*sortTimeout = 1;
}
+ // scan processes first - some header values are calculated there
+ ProcessList_scan(pl, this->state->pauseProcessUpdate);
+ // always update header, especially to avoid gaps in graph meters
+ Header_updateData(this->header);
// force redraw if the number of UID digits was changed
if (Process_uidDigits != oldUidDigits) {
*force_redraw = true;

© 2014-2024 Faster IT GmbH | imprint | privacy policy