Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ static Htop_Reaction actionFilterByUser(State* st) {
Panel_setHeader(usersPanel, "Show processes of:");
Machine* host = st->host;
UsersTable_foreach(host->usersTable, addUserToVector, usersPanel);
Vector_insertionSort(usersPanel->items);
Vector_sort(usersPanel->items, NULL, usersPanel);
ListItem* allUsers = ListItem_new("All users", -1);
Panel_insert(usersPanel, 0, (Object*) allUsers);
const ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 19, false);
Expand Down
4 changes: 2 additions & 2 deletions EnvScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static void EnvScreen_scan(InfoScreen* this) {
InfoScreen_addLine(this, "Could not read process environment.");
}

Vector_insertionSort(this->lines);
Vector_insertionSort(panel->items);
Vector_sort(this->lines, NULL, this);
Vector_sort(panel->items, NULL, this);
Panel_setSelected(panel, idx);
}

Expand Down
3 changes: 2 additions & 1 deletion ListItem.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void ListItem_append(ListItem* this, const char* text) {
this->value[newLen] = '\0';
}

int ListItem_compare(const void* cast1, const void* cast2) {
int ListItem_compare(const void* cast1, const void* cast2, void* context) {
(void)context;
const ListItem* obj1 = (const ListItem*) cast1;
const ListItem* obj2 = (const ListItem*) cast2;
return strcmp(obj1->value, obj2->value);
Expand Down
2 changes: 1 addition & 1 deletion ListItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ListItem* ListItem_new(const char* value, int key);

void ListItem_append(ListItem* this, const char* text);

int ListItem_compare(const void* cast1, const void* cast2);
int ListItem_compare(const void* cast1, const void* cast2, void* context);

static inline const char* ListItem_getRef(const ListItem* this) {
return this->value;
Expand Down
4 changes: 2 additions & 2 deletions Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Object_;
typedef struct Object_ Object;

typedef void(*Object_Display)(const Object*, RichString*);
typedef int(*Object_Compare)(const void*, const void*);
typedef int(*Object_Compare)(const void*, const void*, void*);
typedef void(*Object_Delete)(Object*);

#define Object_getClass(obj_) ((const Object*)(obj_))->klass
Expand All @@ -28,7 +28,7 @@ typedef void(*Object_Delete)(Object*);
#define Object_delete(obj_) (assert(Object_getClass(obj_)->delete), Object_getClass(obj_)->delete((Object*)(obj_)))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) (assert(Object_getClass(obj_)->display), Object_getClass(obj_)->display((const Object*)(obj_), str_))
#define Object_compare(obj_, other_) (assert(Object_getClass(obj_)->compare), Object_getClass(obj_)->compare((const void*)(obj_), other_))
#define Object_compare(obj_, other_, ctx_) (assert(Object_getClass(obj_)->compare), Object_getClass(obj_)->compare((const void*)(obj_), other_, ctx_)

#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))

Expand Down
4 changes: 2 additions & 2 deletions OpenFilesScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ static void OpenFilesScreen_scan(InfoScreen* super) {
OpenFiles_Data_clear(&pdata->data);
}
free(pdata);
Vector_insertionSort(super->lines);
Vector_insertionSort(panel->items);
Vector_sort(super->lines, NULL, super);
Vector_sort(panel->items, NULL, super);
Panel_setSelected(panel, idx);
}

Expand Down
7 changes: 4 additions & 3 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ bool Process_rowSendSignal(Row* super, Arg sgn) {
return Process_sendSignal(this, sgn);
}

int Process_compare(const void* v1, const void* v2) {
int Process_compare(const void* v1, const void* v2, void* context) {
(void)context;
const Process* p1 = (const Process*)v1;
const Process* p2 = (const Process*)v2;

Expand All @@ -928,7 +929,7 @@ int Process_compare(const void* v1, const void* v2) {
return (ScreenSettings_getActiveDirection(ss) == 1) ? result : -result;
}

int Process_compareByParent(const Row* r1, const Row* r2) {
int Process_compareByParent(const Row* r1, const Row* r2, void* context) {
int result = SPACESHIP_NUMBER(
r1->isRoot ? 0 : Row_getGroupOrParent(r1),
r2->isRoot ? 0 : Row_getGroupOrParent(r2)
Expand All @@ -937,7 +938,7 @@ int Process_compareByParent(const Row* r1, const Row* r2) {
if (result != 0)
return result;

return Process_compare(r1, r2);
return Process_compare(r1, r2, context);
}

int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) {
Expand Down
8 changes: 4 additions & 4 deletions Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ typedef int32_t ProcessField; /* see ReservedField list in RowField.h */

// Implemented in platform-specific code:
void Process_writeField(const Process* this, RichString* str, ProcessField field);
int Process_compare(const void* v1, const void* v2);
int Process_compareByParent(const Row* r1, const Row* r2);
int Process_compare(const void* v1, const void* v2, void* context);
int Process_compareByParent(const Row* r1, const Row* r2, void* context);
void Process_delete(Object* cast);
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
#define Process_pidDigits Row_pidDigits
Expand Down Expand Up @@ -317,8 +317,8 @@ bool Process_rowIsVisible(const Row* super, const struct Table_* table);

bool Process_rowMatchesFilter(const Row* super, const struct Table_* table);

static inline int Process_pidEqualCompare(const void* v1, const void* v2) {
return Row_idEqualCompare(v1, v2);
static inline int Process_pidEqualCompare(const void* v1, const void* v2, void* context) {
return Row_idEqualCompare(v1, v2, context);
}

int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key);
Expand Down
4 changes: 2 additions & 2 deletions ProcessLocksScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static void ProcessLocksScreen_scan(InfoScreen* this) {
}
}
free(pdata);
Vector_insertionSort(this->lines);
Vector_insertionSort(panel->items);
Vector_sort(this->lines, NULL, this);
Vector_sort(panel->items, NULL, this);
Panel_setSelected(panel, idx);
}

Expand Down
7 changes: 4 additions & 3 deletions Row.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,15 @@ void Row_toggleTag(Row* this) {
this->tag = !this->tag;
}

int Row_compare(const void* v1, const void* v2) {
int Row_compare(const void* v1, const void* v2, void* context) {
(void)context;
const Row* r1 = (const Row*)v1;
const Row* r2 = (const Row*)v2;

return SPACESHIP_NUMBER(r1->id, r2->id);
}

int Row_compareByParent_Base(const void* v1, const void* v2) {
int Row_compareByParent_Base(const void* v1, const void* v2, void* context) {
const Row* r1 = (const Row*)v1;
const Row* r2 = (const Row*)v2;

Expand All @@ -549,7 +550,7 @@ int Row_compareByParent_Base(const void* v1, const void* v2) {
if (result != 0)
return result;

return Row_compare(v1, v2);
return Row_compare(v1, v2, context);
}

const RowClass Row_class = {
Expand Down
11 changes: 6 additions & 5 deletions Row.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ typedef bool (*Row_IsHighlighted)(const Row*);
typedef bool (*Row_IsVisible)(const Row*, const struct Table_*);
typedef bool (*Row_MatchesFilter)(const Row*, const struct Table_*);
typedef const char* (*Row_SortKeyString)(Row*);
typedef int (*Row_CompareByParent)(const Row*, const Row*);
typedef int (*Row_CompareByParent)(const Row*, const Row*, void*);

int Row_compare(const void* v1, const void* v2);
int Row_compare(const void* v1, const void* v2, void* context);

typedef struct RowClass_ {
const ObjectClass super;
Expand All @@ -102,7 +102,7 @@ typedef struct RowClass_ {
#define Row_isVisible(r_, t_) (As_Row(r_)->isVisible ? (As_Row(r_)->isVisible(r_, t_)) : true)
#define Row_matchesFilter(r_, t_) (As_Row(r_)->matchesFilter ? (As_Row(r_)->matchesFilter(r_, t_)) : false)
#define Row_sortKeyString(r_) (As_Row(r_)->sortKeyString ? (As_Row(r_)->sortKeyString(r_)) : "")
#define Row_compareByParent(r1_, r2_) (As_Row(r1_)->compareByParent ? (As_Row(r1_)->compareByParent(r1_, r2_)) : Row_compareByParent_Base(r1_, r2_))
#define Row_compareByParent(r1_, r2_, ctx_) (As_Row(r1_)->compareByParent ? (As_Row(r1_)->compareByParent(r1_, r2_, ctx_)) : Row_compareByParent_Base(r1_, r2_, ctx_))

#define ONE_K 1024UL
#define ONE_M (ONE_K * ONE_K)
Expand Down Expand Up @@ -162,7 +162,8 @@ void Row_printRate(RichString* str, double rate, bool coloring);

int Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr);

static inline int Row_idEqualCompare(const void* v1, const void* v2) {
static inline int Row_idEqualCompare(const void* v1, const void* v2, void* context) {
(void)context;
const int p1 = ((const Row*)v1)->id;
const int p2 = ((const Row*)v2)->id;
return p1 != p2; /* return zero when equal */
Expand All @@ -177,6 +178,6 @@ static inline bool Row_isChildOf(const Row* this, int id) {
return id == Row_getGroupOrParent(this);
}

int Row_compareByParent_Base(const void* v1, const void* v2);
int Row_compareByParent_Base(const void* v1, const void* v2, void* context);

#endif
8 changes: 4 additions & 4 deletions Table.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ static void Table_buildTreeBranch(Table* this, int rowid, unsigned int level, in
}
}

static int compareRowByKnownParentThenNatural(const void* v1, const void* v2) {
return Row_compareByParent((const Row*) v1, (const Row*) v2);
static int compareRowByKnownParentThenNatural(const void* v1, const void* v2, void* context) {
return Row_compareByParent((const Row*) v1, (const Row*) v2, context);
}

// Builds a sorted tree from scratch, without relying on previously gathered information
Expand Down Expand Up @@ -168,7 +168,7 @@ static void Table_buildTree(Table* this) {
}

// Sort by known parent (roots first), then row ID
Vector_quickSortCustomCompare(this->rows, compareRowByKnownParentThenNatural);
Vector_sort(this->rows, compareRowByKnownParentThenNatural, this);

// Find all processes whose parent is not visible
for (int i = 0; i < vsize; i++) {
Expand Down Expand Up @@ -199,7 +199,7 @@ void Table_updateDisplayList(Table* this) {
Table_buildTree(this);
} else {
if (this->needsSort)
Vector_insertionSort(this->rows);
Vector_sort(this->rows, NULL, this);
Vector_prune(this->displayList);
int size = Vector_size(this->rows);
for (int i = 0; i < size; i++)
Expand Down
Loading
Loading