mirror of https://github.com/xzeldon/htop.git
Hold only a const version of Settings in ProcessList
This commit is contained in:
parent
4eb443926f
commit
a3bb7cbe64
|
@ -67,7 +67,7 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
|
||||||
|
|
||||||
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
void ProcessList_printHeader(ProcessList* this, RichString* header) {
|
||||||
RichString_prune(header);
|
RichString_prune(header);
|
||||||
ProcessField* fields = this->settings->fields;
|
const ProcessField* fields = this->settings->fields;
|
||||||
for (int i = 0; fields[i]; i++) {
|
for (int i = 0; fields[i]; i++) {
|
||||||
const char* field = Process_fields[fields[i]].title;
|
const char* field = Process_fields[fields[i]].title;
|
||||||
if (!field) field = "- ";
|
if (!field) field = "- ";
|
||||||
|
@ -142,20 +142,21 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
|
||||||
Vector_delete(children);
|
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) {
|
void ProcessList_sort(ProcessList* this) {
|
||||||
if (!this->settings->treeView) {
|
if (!this->settings->treeView) {
|
||||||
Vector_insertionSort(this->processes);
|
Vector_insertionSort(this->processes);
|
||||||
} else {
|
} else {
|
||||||
// Save settings
|
// Save settings
|
||||||
int direction = this->settings->direction;
|
int direction = this->settings->direction;
|
||||||
int sortKey = this->settings->sortKey;
|
|
||||||
// Sort by PID
|
// Sort by PID
|
||||||
this->settings->sortKey = PID;
|
Vector_quickSortCustomCompare(this->processes, ProcessList_treeProcessCompare);
|
||||||
this->settings->direction = 1;
|
|
||||||
Vector_quickSort(this->processes);
|
|
||||||
// Restore settings
|
|
||||||
this->settings->sortKey = sortKey;
|
|
||||||
this->settings->direction = direction;
|
|
||||||
int vsize = Vector_size(this->processes);
|
int vsize = Vector_size(this->processes);
|
||||||
// Find all processes whose parent is not visible
|
// Find all processes whose parent is not visible
|
||||||
int size;
|
int size;
|
||||||
|
@ -214,7 +215,7 @@ void ProcessList_sort(ProcessList* this) {
|
||||||
|
|
||||||
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
|
ProcessField ProcessList_keyAt(ProcessList* this, int at) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
ProcessField* fields = this->settings->fields;
|
const ProcessField* fields = this->settings->fields;
|
||||||
ProcessField field;
|
ProcessField field;
|
||||||
for (int i = 0; (field = fields[i]); i++) {
|
for (int i = 0; (field = fields[i]); i++) {
|
||||||
const char* title = Process_fields[field].title;
|
const char* title = Process_fields[field].title;
|
||||||
|
|
|
@ -35,7 +35,7 @@ in the source distribution for its full text.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct ProcessList_ {
|
typedef struct ProcessList_ {
|
||||||
Settings* settings;
|
const Settings* settings;
|
||||||
|
|
||||||
Vector* processes;
|
Vector* processes;
|
||||||
Vector* processes2;
|
Vector* processes2;
|
||||||
|
|
6
Vector.c
6
Vector.c
|
@ -161,10 +161,10 @@ static void insertionSort(Object** array, int left, int right, Object_Compare co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector_quickSort(Vector* this) {
|
void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare) {
|
||||||
assert(this->type->compare);
|
assert(compare);
|
||||||
assert(Vector_isConsistent(this));
|
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));
|
assert(Vector_isConsistent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
Vector.h
5
Vector.h
|
@ -31,7 +31,10 @@ void Vector_delete(Vector* this);
|
||||||
|
|
||||||
void Vector_prune(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);
|
void Vector_insertionSort(Vector* this);
|
||||||
|
|
||||||
|
|
|
@ -362,7 +362,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
|
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
|
||||||
DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this;
|
DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this;
|
||||||
Settings* settings = this->settings;
|
const Settings* settings = this->settings;
|
||||||
bool hideKernelThreads = settings->hideKernelThreads;
|
bool hideKernelThreads = settings->hideKernelThreads;
|
||||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||||
|
|
||||||
|
|
|
@ -382,7 +382,7 @@ IGNORE_WCASTQUAL_END
|
||||||
|
|
||||||
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
|
void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
|
||||||
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this;
|
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this;
|
||||||
Settings* settings = this->settings;
|
const Settings* settings = this->settings;
|
||||||
bool hideKernelThreads = settings->hideKernelThreads;
|
bool hideKernelThreads = settings->hideKernelThreads;
|
||||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||||
|
|
||||||
|
|
|
@ -936,7 +936,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
|
||||||
ProcessList* pl = (ProcessList*) this;
|
ProcessList* pl = (ProcessList*) this;
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
Settings* settings = pl->settings;
|
const Settings* settings = pl->settings;
|
||||||
|
|
||||||
#ifdef HAVE_TASKSTATS
|
#ifdef HAVE_TASKSTATS
|
||||||
unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL;
|
unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL;
|
||||||
|
|
|
@ -185,7 +185,7 @@ static double getpcpu(const struct kinfo_proc *kp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
|
static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
|
||||||
Settings* settings = this->super.settings;
|
const Settings* settings = this->super.settings;
|
||||||
bool hideKernelThreads = settings->hideKernelThreads;
|
bool hideKernelThreads = settings->hideKernelThreads;
|
||||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||||
struct kinfo_proc* kproc;
|
struct kinfo_proc* kproc;
|
||||||
|
|
Loading…
Reference in New Issue