diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2020-12-17 20:09:55 -0300 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-12-19 16:02:34 +0100 |
commit | 3d1703f16faf5bd3c73976909e1b6e03061a7f72 (patch) | |
tree | 45dbb3c0be0817b833b9d4a64376d9033b5ef2fe /linux/LinuxProcess.c | |
parent | 52fa4e7ee4816209ad82ba92ece8a3dc5b25ddd0 (diff) |
Invert Process_compare resolution so that superclass matches run first
* This removes duplicated code that adjusts the sort direction from every
OS-specific folder.
* Most fields in a regular htop screen are OS-independent, so trying
Process_compare first and only falling back to the OS-specific
compareByKey function if it's an OS-specific field makes sense.
* This will allow us to override the sortKey in a global way without having
to edit each OS-specific file.
Diffstat (limited to 'linux/LinuxProcess.c')
-rw-r--r-- | linux/LinuxProcess.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8cd9f492..9e184b64 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -767,19 +767,11 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces RichString_appendWide(str, attr, buffer); } -static long LinuxProcess_compare(const void* v1, const void* v2) { - const LinuxProcess *p1, *p2; - const Settings *settings = ((const Process*)v1)->settings; +static long LinuxProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const LinuxProcess* p1 = (const LinuxProcess*)v1; + const LinuxProcess* p2 = (const LinuxProcess*)v2; - if (settings->direction == 1) { - p1 = (const LinuxProcess*)v1; - p2 = (const LinuxProcess*)v2; - } else { - p2 = (const LinuxProcess*)v1; - p1 = (const LinuxProcess*)v2; - } - - switch ((int)settings->sortKey) { + switch ((int) key) { case M_DRS: return SPACESHIP_NUMBER(p2->m_drs, p1->m_drs); case M_DT: @@ -865,7 +857,7 @@ static long LinuxProcess_compare(const void* v1, const void* v2) { case CWD: return SPACESHIP_NULLSTR(p1->cwd, p2->cwd); default: - return Process_compare(v1, v2); + return SPACESHIP_NUMBER(v1->pid, v2->pid); } } @@ -878,8 +870,9 @@ const ProcessClass LinuxProcess_class = { .extends = Class(Process), .display = Process_display, .delete = Process_delete, - .compare = LinuxProcess_compare + .compare = Process_compare }, .writeField = LinuxProcess_writeField, - .getCommandStr = LinuxProcess_getCommandStr + .getCommandStr = LinuxProcess_getCommandStr, + .compareByKey = LinuxProcess_compareByKey }; |