From 86b155b83f5db87fb18a9bc677c6718963c7451d Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sun, 13 Sep 2015 00:00:00 -0500 Subject: [PATCH] library: make the pids_sort_order enums more intuitive The values of PROCPS_SORT_ASCEND & PROCPS_SORT_DESCEND were a tad unintuitive. This patch will just make them a more natural +1 for ascending and -1 for descending. [ plus it still allows that fast path multiplication ] [ instead of a comparison for signed numbers/strings ] Signed-off-by: Jim Warner --- proc/pids.c | 12 ++++++------ proc/pids.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/proc/pids.c b/proc/pids.c index d35fca2b..6be88d81 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -262,14 +262,14 @@ struct sort_parms { const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { \ const struct pids_result *a = (*A)->head + P->offset; \ const struct pids_result *b = (*B)->head + P->offset; \ - return P->order * (b->result. T - a->result. T); } + return P->order * (a->result. T - b->result. T); } #define REG_srt(T) static int srtNAME(T) ( \ const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { \ const struct pids_result *a = (*A)->head + P->offset; \ const struct pids_result *b = (*B)->head + P->offset; \ - if ( a->result. T > b->result. T ) return P->order > 0 ? -1 : 1; \ - if ( a->result. T < b->result. T ) return P->order > 0 ? 1 : -1; \ + if ( a->result. T > b->result. T ) return P->order > 0 ? 1 : -1; \ + if ( a->result. T < b->result. T ) return P->order > 0 ? -1 : 1; \ return 0; } NUM_srt(s_ch) @@ -284,7 +284,7 @@ static int srtNAME(str) ( const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { const struct pids_result *a = (*A)->head + P->offset; const struct pids_result *b = (*B)->head + P->offset; - return P->order * strcoll(b->result.str, a->result.str); + return P->order * strcoll(a->result.str, b->result.str); } static int srtNAME(strv) ( @@ -292,14 +292,14 @@ static int srtNAME(strv) ( const struct pids_result *a = (*A)->head + P->offset; const struct pids_result *b = (*B)->head + P->offset; if (!a->result.strv || !b->result.strv) return 0; - return P->order * strcoll((*b->result.strv), (*a->result.strv)); + return P->order * strcoll((*a->result.strv), (*b->result.strv)); } static int srtNAME(strvers) ( const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) { const struct pids_result *a = (*A)->head + P->offset; const struct pids_result *b = (*B)->head + P->offset; - return P->order * strverscmp(b->result.str, a->result.str); + return P->order * strverscmp(a->result.str, b->result.str); } static int srtNAME(noop) ( diff --git a/proc/pids.h b/proc/pids.h index ca43dfa7..dc9ee6b5 100644 --- a/proc/pids.h +++ b/proc/pids.h @@ -150,8 +150,8 @@ enum pids_reap_type { }; enum pids_sort_order { - PROCPS_SORT_ASCEND = -1, - PROCPS_SORT_DESCEND = +1 + PROCPS_SORT_ASCEND = +1, + PROCPS_SORT_DESCEND = -1 };