From 319ff3228363986ed8d02b4161ec6530bc0b9144 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Sun, 30 May 2010 17:49:26 +0200 Subject: [PATCH] shorten top compare functions A substraction is used instead of if, else if, else. This is much shorter. Signed-off-by: Alexander Graf --- src/top.cc | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/top.cc b/src/top.cc index 58fda0fa..020d6a04 100644 --- a/src/top.cc +++ b/src/top.cc @@ -255,13 +255,7 @@ static int compare_cpu(void *va, void *vb) { struct process *a = (struct process *)va, *b = (struct process *)vb; - if (a->amount < b->amount) { - return 1; - } else if (a->amount > b->amount) { - return -1; - } else { - return 0; - } + return b->amount - a->amount; } /* 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; - if (a->rss < b->rss) { - return 1; - } else if (a->rss > b->rss) { - return -1; - } else { - return 0; - } + return b->rss - a->rss; } /* 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; - if (a->io_perc < b->io_perc) { - return 1; - } else if (a->io_perc > b->io_perc) { - return -1; - } else { - return 0; - } + return b->io_perc - a->io_perc; } #endif /* BUILD_IOSTATS */