Skip to content

Commit a3a7958

Browse files
tanriolBenBE
authored andcommitted
ProcessList: sort before panel rebuild if needed
1 parent 4aeb146 commit a3a7958

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Action.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ static Htop_Reaction actionSetSortColumn(State* st) {
189189
}
190190
Object_delete(sortPanel);
191191

192-
if (st->pauseProcessUpdate)
193-
ProcessList_sort(st->pl);
192+
st->pl->needsSort = true;
194193

195194
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
196195
}
@@ -281,8 +280,7 @@ static Htop_Reaction actionLowerPriority(State* st) {
281280

282281
static Htop_Reaction actionInvertSortOrder(State* st) {
283282
ScreenSettings_invertSortOrder(st->settings->ss);
284-
if (st->pauseProcessUpdate)
285-
ProcessList_sort(st->pl);
283+
st->pl->needsSort = true;
286284
return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING;
287285
}
288286

ProcessList.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users
2727
this->processTable = Hashtable_new(200, false);
2828
this->displayTreeSet = Hashtable_new(200, false);
2929
this->draftingTreeSet = Hashtable_new(200, false);
30+
this->needsSort = true;
3031

3132
this->usersTable = usersTable;
3233
this->pidMatchList = pidMatchList;
@@ -496,6 +497,7 @@ void ProcessList_sort(ProcessList* this) {
496497
} else {
497498
Vector_insertionSort(this->processes);
498499
}
500+
this->needsSort = false;
499501
}
500502

501503
ProcessField ProcessList_keyAt(const ProcessList* this, int at) {
@@ -531,6 +533,9 @@ void ProcessList_collapseAllBranches(ProcessList* this) {
531533
}
532534

533535
void ProcessList_rebuildPanel(ProcessList* this) {
536+
if (this->needsSort)
537+
ProcessList_sort(this);
538+
534539
const char* incFilter = this->incFilter;
535540

536541
const int currPos = Panel_getSelectedIndex(this->panel);

ProcessList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct ProcessList_ {
5050

5151
Hashtable* displayTreeSet;
5252
Hashtable* draftingTreeSet;
53+
bool needsSort;
5354

5455
Hashtable* dynamicMeters; /* runtime-discovered meters */
5556
Hashtable* dynamicColumns; /* runtime-discovered Columns */

ScreenManager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
126126
// always update header, especially to avoid gaps in graph meters
127127
Header_updateData(this->header);
128128
if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) {
129-
ProcessList_sort(pl);
129+
pl->needsSort = true;
130130
*sortTimeout = 1;
131131
}
132132
// force redraw if the number of UID digits was changed

0 commit comments

Comments
 (0)