tree-wide: Convert compare_func's to use CMP() macro wherever possible.

Looked for definitions of functions using the *_compare_func() suffix.

Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
This commit is contained in:
Filipe Brandenburger
2018-08-06 19:26:35 -07:00
parent 26cdf3e50b
commit a0edd02e43
14 changed files with 86 additions and 120 deletions
+3 -3
View File
@@ -71,7 +71,7 @@ void trivial_hash_func(const void *p, struct siphash *state) {
}
int trivial_compare_func(const void *a, const void *b) {
return a < b ? -1 : (a > b ? 1 : 0);
return CMP(a, b);
}
const struct hash_ops trivial_hash_ops = {
@@ -87,7 +87,7 @@ int uint64_compare_func(const void *_a, const void *_b) {
uint64_t a, b;
a = *(const uint64_t*) _a;
b = *(const uint64_t*) _b;
return a < b ? -1 : (a > b ? 1 : 0);
return CMP(a, b);
}
const struct hash_ops uint64_hash_ops = {
@@ -104,7 +104,7 @@ int devt_compare_func(const void *_a, const void *_b) {
dev_t a, b;
a = *(const dev_t*) _a;
b = *(const dev_t*) _b;
return a < b ? -1 : (a > b ? 1 : 0);
return CMP(a, b);
}
const struct hash_ops devt_hash_ops = {
+4 -2
View File
@@ -581,9 +581,11 @@ void in_addr_data_hash_func(const void *p, struct siphash *state) {
int in_addr_data_compare_func(const void *a, const void *b) {
const struct in_addr_data *x = a, *y = b;
int r;
if (x->family != y->family)
return x->family - y->family;
r = CMP(x->family, y->family);
if (r != 0)
return r;
return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));
}
+1 -6
View File
@@ -1108,12 +1108,7 @@ int pid_compare_func(const void *a, const void *b) {
const pid_t *p = a, *q = b;
/* Suitable for usage in qsort() */
if (*p < *q)
return -1;
if (*p > *q)
return 1;
return 0;
return CMP(*p, *q);
}
int ioprio_parse_priority(const char *s, int *ret) {