mirror of https://github.com/xzeldon/htop.git
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.
This commit is contained in:
parent
82dce5cf8e
commit
fa3e0d06c2
|
@ -404,7 +404,7 @@ static int ProcessList_treeProcessCompare(const void* v1, const void* v2) {
|
||||||
return SPACESHIP_NUMBER(p1->tree_left, p2->tree_left);
|
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* p1 = (const Process*)v1;
|
||||||
const Process* p2 = (const Process*)v2;
|
const Process* p2 = (const Process*)v2;
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ static int compareProcessByKnownParentThenPID(const void* v1, const void* v2) {
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
return result;
|
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
|
// 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
|
// 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
|
// Find all processes whose parent is not visible
|
||||||
for (int i = 0; i < vsize; i++) {
|
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
|
// Check consistency of the built structures
|
||||||
assert(Vector_size(this->displayList) == vsize); (void)vsize;
|
assert(Vector_size(this->displayList) == vsize); (void)vsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_updateDisplayList(ProcessList* this) {
|
void ProcessList_updateDisplayList(ProcessList* this) {
|
||||||
if (this->settings->ss->treeView) {
|
if (this->settings->ss->treeView) {
|
||||||
ProcessList_updateTreeSet(this);
|
if (this->needsSort)
|
||||||
Vector_quickSortCustomCompare(this->displayList, ProcessList_treeProcessCompare);
|
ProcessList_buildTree(this);
|
||||||
} else {
|
} else {
|
||||||
if (this->needsSort)
|
if (this->needsSort)
|
||||||
Vector_insertionSort(this->processes);
|
Vector_insertionSort(this->processes);
|
||||||
|
|
|
@ -121,14 +121,14 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
|
||||||
if (*rescan) {
|
if (*rescan) {
|
||||||
*oldTime = newTime;
|
*oldTime = newTime;
|
||||||
int oldUidDigits = Process_uidDigits;
|
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)) {
|
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
|
||||||
pl->needsSort = true;
|
pl->needsSort = true;
|
||||||
*sortTimeout = 1;
|
*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
|
// force redraw if the number of UID digits was changed
|
||||||
if (Process_uidDigits != oldUidDigits) {
|
if (Process_uidDigits != oldUidDigits) {
|
||||||
*force_redraw = true;
|
*force_redraw = true;
|
||||||
|
|
Loading…
Reference in New Issue