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 <james.warner@comcast.net>
This commit is contained in:
parent
872be3a3a2
commit
86b155b83f
12
proc/pids.c
12
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) (
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user