Skip to content

Commit fa3e0d0

Browse files
tanriolBenBE
authored andcommitted
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.
1 parent 82dce5c commit fa3e0d0

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

ProcessList.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int ProcessList_treeProcessCompare(const void* v1, const void* v2) {
404404
return SPACESHIP_NUMBER(p1->tree_left, p2->tree_left);
405405
}
406406

407-
static int compareProcessByKnownParentThenPID(const void* v1, const void* v2) {
407+
static int compareProcessByKnownParentThenNatural(const void* v1, const void* v2) {
408408
const Process* p1 = (const Process*)v1;
409409
const Process* p2 = (const Process*)v2;
410410

@@ -416,7 +416,7 @@ static int compareProcessByKnownParentThenPID(const void* v1, const void* v2) {
416416
if (result != 0)
417417
return result;
418418

419-
return SPACESHIP_NUMBER(p1->pid, p2->pid);
419+
return Process_compare(v1, v2);
420420
}
421421

422422
// Builds a sorted tree from scratch, without relying on previously gathered information
@@ -449,7 +449,7 @@ static void ProcessList_buildTree(ProcessList* this) {
449449
}
450450

451451
// Sort by known parent PID (roots first), then PID
452-
Vector_quickSortCustomCompare(this->processes, compareProcessByKnownParentThenPID);
452+
Vector_quickSortCustomCompare(this->processes, compareProcessByKnownParentThenNatural);
453453

454454
// Find all processes whose parent is not visible
455455
for (int i = 0; i < vsize; i++) {
@@ -470,14 +470,16 @@ static void ProcessList_buildTree(ProcessList* this) {
470470
}
471471
}
472472

473+
this->needsSort = false;
474+
473475
// Check consistency of the built structures
474476
assert(Vector_size(this->displayList) == vsize); (void)vsize;
475477
}
476478

477479
void ProcessList_updateDisplayList(ProcessList* this) {
478480
if (this->settings->ss->treeView) {
479-
ProcessList_updateTreeSet(this);
480-
Vector_quickSortCustomCompare(this->displayList, ProcessList_treeProcessCompare);
481+
if (this->needsSort)
482+
ProcessList_buildTree(this);
481483
} else {
482484
if (this->needsSort)
483485
Vector_insertionSort(this->processes);

ScreenManager.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
121121
if (*rescan) {
122122
*oldTime = newTime;
123123
int oldUidDigits = Process_uidDigits;
124-
// scan processes first - some header values are calculated there
125-
ProcessList_scan(pl, this->state->pauseProcessUpdate);
126-
// always update header, especially to avoid gaps in graph meters
127-
Header_updateData(this->header);
128124
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
129125
pl->needsSort = true;
130126
*sortTimeout = 1;
131127
}
128+
// scan processes first - some header values are calculated there
129+
ProcessList_scan(pl, this->state->pauseProcessUpdate);
130+
// always update header, especially to avoid gaps in graph meters
131+
Header_updateData(this->header);
132132
// force redraw if the number of UID digits was changed
133133
if (Process_uidDigits != oldUidDigits) {
134134
*force_redraw = true;

0 commit comments

Comments
 (0)