1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +00:00

shorten top compare functions

A substraction is used instead of if, else if, else.  This is much
shorter.

Signed-off-by: Alexander Graf <agraf@znc.in>
This commit is contained in:
Alexander Graf 2010-05-30 17:49:26 +02:00
parent bf7c2bafc2
commit 319ff32283

View File

@ -255,13 +255,7 @@ static int compare_cpu(void *va, void *vb)
{ {
struct process *a = (struct process *)va, *b = (struct process *)vb; struct process *a = (struct process *)va, *b = (struct process *)vb;
if (a->amount < b->amount) { return b->amount - a->amount;
return 1;
} else if (a->amount > b->amount) {
return -1;
} else {
return 0;
}
} }
/* mem comparison function for prio queue */ /* mem comparison function for prio queue */
@ -269,13 +263,7 @@ static int compare_mem(void *va, void *vb)
{ {
struct process *a = (struct process *)va, *b = (struct process *)vb; struct process *a = (struct process *)va, *b = (struct process *)vb;
if (a->rss < b->rss) { return b->rss - a->rss;
return 1;
} else if (a->rss > b->rss) {
return -1;
} else {
return 0;
}
} }
/* CPU time comparision function for prio queue */ /* CPU time comparision function for prio queue */
@ -292,13 +280,7 @@ static int compare_io(void *va, void *vb)
{ {
struct process *a = (struct process *)va, *b = (struct process *)vb; struct process *a = (struct process *)va, *b = (struct process *)vb;
if (a->io_perc < b->io_perc) { return b->io_perc - a->io_perc;
return 1;
} else if (a->io_perc > b->io_perc) {
return -1;
} else {
return 0;
}
} }
#endif /* BUILD_IOSTATS */ #endif /* BUILD_IOSTATS */