Hold only a const version of Settings in ProcessList

This commit is contained in:
Christian Göttsche 2020-10-21 21:26:09 +02:00 committed by cgzones
parent 4eb443926f
commit a3bb7cbe64
8 changed files with 22 additions and 18 deletions

View File

@ -67,7 +67,7 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
void ProcessList_printHeader(ProcessList* this, RichString* header) {
RichString_prune(header);
ProcessField* fields = this->settings->fields;
const ProcessField* fields = this->settings->fields;
for (int i = 0; fields[i]; i++) {
const char* field = Process_fields[fields[i]].title;
if (!field) field = "- ";
@ -142,20 +142,21 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
Vector_delete(children);
}
static long ProcessList_treeProcessCompare(const void* v1, const void* v2) {
const Process *p1 = (const Process*)v1;
const Process *p2 = (const Process*)v2;
return p1->pid - p2->pid;
}
void ProcessList_sort(ProcessList* this) {
if (!this->settings->treeView) {
Vector_insertionSort(this->processes);
} else {
// Save settings
int direction = this->settings->direction;
int sortKey = this->settings->sortKey;
// Sort by PID
this->settings->sortKey = PID;
this->settings->direction = 1;
Vector_quickSort(this->processes);
// Restore settings
this->settings->sortKey = sortKey;
this->settings->direction = direction;
Vector_quickSortCustomCompare(this->processes, ProcessList_treeProcessCompare);
int vsize = Vector_size(this->processes);
// Find all processes whose parent is not visible
int size;
@ -214,7 +215,7 @@ void ProcessList_sort(ProcessList* this) {
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
int x = 0;
ProcessField* fields = this->settings->fields;
const ProcessField* fields = this->settings->fields;
ProcessField field;
for (int i = 0; (field = fields[i]); i++) {
const char* title = Process_fields[field].title;

View File

@ -35,7 +35,7 @@ in the source distribution for its full text.
#endif
typedef struct ProcessList_ {
Settings* settings;
const Settings* settings;
Vector* processes;
Vector* processes2;

View File

@ -161,10 +161,10 @@ static void insertionSort(Object** array, int left, int right, Object_Compare co
}
}
void Vector_quickSort(Vector* this) {
assert(this->type->compare);
void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare) {
assert(compare);
assert(Vector_isConsistent(this));
quickSort(this->array, 0, this->items - 1, this->type->compare);
quickSort(this->array, 0, this->items - 1, compare);
assert(Vector_isConsistent(this));
}

View File

@ -31,7 +31,10 @@ void Vector_delete(Vector* this);
void Vector_prune(Vector* this);
void Vector_quickSort(Vector* this);
void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare);
static inline void Vector_quickSort(Vector* this) {
Vector_quickSortCustomCompare(this, this->type->compare);
}
void Vector_insertionSort(Vector* this);

View File

@ -362,7 +362,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this;
Settings* settings = this->settings;
const Settings* settings = this->settings;
bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads;

View File

@ -382,7 +382,7 @@ IGNORE_WCASTQUAL_END
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this;
Settings* settings = this->settings;
const Settings* settings = this->settings;
bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads;

View File

@ -936,7 +936,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
ProcessList* pl = (ProcessList*) this;
DIR* dir;
struct dirent* entry;
Settings* settings = pl->settings;
const Settings* settings = pl->settings;
#ifdef HAVE_TASKSTATS
unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL;

View File

@ -185,7 +185,7 @@ static double getpcpu(const struct kinfo_proc *kp) {
}
static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
Settings* settings = this->super.settings;
const Settings* settings = this->super.settings;
bool hideKernelThreads = settings->hideKernelThreads;
bool hideUserlandThreads = settings->hideUserlandThreads;
struct kinfo_proc* kproc;