summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-21 21:26:09 +0200
committercgzones <cgzones@googlemail.com>2020-10-26 19:30:38 +0100
commita3bb7cbe649d9c718b65aded4c6b2445ff5d20d5 (patch)
tree0777ed5bf2fe322227fe114cd1126ab77bc8ccf1
parent4eb443926f9944f4c100b1aabfb5553cbbd98874 (diff)
Hold only a const version of Settings in ProcessList
-rw-r--r--ProcessList.c19
-rw-r--r--ProcessList.h2
-rw-r--r--Vector.c6
-rw-r--r--Vector.h5
-rw-r--r--dragonflybsd/DragonFlyBSDProcessList.c2
-rw-r--r--freebsd/FreeBSDProcessList.c2
-rw-r--r--linux/LinuxProcessList.c2
-rw-r--r--openbsd/OpenBSDProcessList.c2
8 files changed, 22 insertions, 18 deletions
diff --git a/ProcessList.c b/ProcessList.c
index f2cdcf94..dac86cb8 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -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;
diff --git a/ProcessList.h b/ProcessList.h
index 07fe48bc..4c09e4ce 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -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;
diff --git a/Vector.c b/Vector.c
index 1dfccc44..4ed0d53d 100644
--- a/Vector.c
+++ b/Vector.c
@@ -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));
}
diff --git a/Vector.h b/Vector.h
index 3cff212c..70df3e4a 100644
--- a/Vector.h
+++ b/Vector.h
@@ -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);
diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c
index 7fcee410..d6eb38a5 100644
--- a/dragonflybsd/DragonFlyBSDProcessList.c
+++ b/dragonflybsd/DragonFlyBSDProcessList.c
@@ -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;
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 4e418446..28cdf859 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -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;
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 0903531a..5195c616 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -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;
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index 693ec9db..320b693b 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -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;

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