tree-wide: CMP()ify all the things
Let's employ coccinelle to fix everything up automatically for us.
This commit is contained in:
parent
f7eed93f15
commit
6dd91b3682
28
coccinelle/cmp.cocci
Normal file
28
coccinelle/cmp.cocci
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
@@
|
||||||
|
expression x, y;
|
||||||
|
@@
|
||||||
|
- if (x < y)
|
||||||
|
- return -1;
|
||||||
|
- if (x > y)
|
||||||
|
- return 1;
|
||||||
|
- return 0;
|
||||||
|
+ return CMP(x, y);
|
||||||
|
@@
|
||||||
|
expression x, y;
|
||||||
|
@@
|
||||||
|
- if (x < y)
|
||||||
|
- return -1;
|
||||||
|
- else if (x > y)
|
||||||
|
- return 1;
|
||||||
|
- return 0;
|
||||||
|
+ return CMP(x, y);
|
||||||
|
@@
|
||||||
|
expression x, y;
|
||||||
|
@@
|
||||||
|
- if (x < y)
|
||||||
|
- return -1;
|
||||||
|
- else if (x > y)
|
||||||
|
- return 1;
|
||||||
|
- else
|
||||||
|
- return 0;
|
||||||
|
+ return CMP(x, y);
|
|
@ -418,12 +418,7 @@ static int btrfs_ioctl_search_args_compare(const struct btrfs_ioctl_search_args
|
||||||
if (args->key.min_type > args->key.max_type)
|
if (args->key.min_type > args->key.max_type)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (args->key.min_offset < args->key.max_offset)
|
return CMP(args->key.min_offset, args->key.max_offset);
|
||||||
return -1;
|
|
||||||
if (args->key.min_offset > args->key.max_offset)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) \
|
#define FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) \
|
||||||
|
|
|
@ -688,32 +688,16 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case TABLE_TIMESTAMP:
|
case TABLE_TIMESTAMP:
|
||||||
if (a->timestamp < b->timestamp)
|
return CMP(a->timestamp, b->timestamp);
|
||||||
return -1;
|
|
||||||
if (a->timestamp > b->timestamp)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case TABLE_TIMESPAN:
|
case TABLE_TIMESPAN:
|
||||||
if (a->timespan < b->timespan)
|
return CMP(a->timespan, b->timespan);
|
||||||
return -1;
|
|
||||||
if (a->timespan > b->timespan)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case TABLE_SIZE:
|
case TABLE_SIZE:
|
||||||
if (a->size < b->size)
|
return CMP(a->size, b->size);
|
||||||
return -1;
|
|
||||||
if (a->size > b->size)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case TABLE_UINT32:
|
case TABLE_UINT32:
|
||||||
if (a->uint32 < b->uint32)
|
return CMP(a->uint32, b->uint32);
|
||||||
return -1;
|
|
||||||
if (a->uint32 > b->uint32)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
|
@ -721,12 +705,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic fallback using the orginal order in which the cells where added. */
|
/* Generic fallback using the orginal order in which the cells where added. */
|
||||||
if (index_a < index_b)
|
return CMP(index_a, index_b);
|
||||||
return -1;
|
|
||||||
if (index_a > index_b)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
|
static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
|
||||||
|
|
|
@ -398,12 +398,7 @@ int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m) {
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (n < m)
|
return CMP(n, m);
|
||||||
return -1;
|
|
||||||
else if (n > m)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool chars_intersect(const char *a, const char *b) {
|
bool chars_intersect(const char *a, const char *b) {
|
||||||
|
|
|
@ -496,11 +496,7 @@ static int peer_address_compare_func(const void *a, const void *b) {
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return memcmp(&x->peer.in6.sin6_addr, &y->peer.in6.sin6_addr, sizeof(x->peer.in6.sin6_addr));
|
return memcmp(&x->peer.in6.sin6_addr, &y->peer.in6.sin6_addr, sizeof(x->peer.in6.sin6_addr));
|
||||||
case AF_VSOCK:
|
case AF_VSOCK:
|
||||||
if (x->peer.vm.svm_cid < y->peer.vm.svm_cid)
|
return CMP(x->peer.vm.svm_cid, y->peer.vm.svm_cid);
|
||||||
return -1;
|
|
||||||
if (x->peer.vm.svm_cid > y->peer.vm.svm_cid)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
assert_not_reached("Black sheep in the family!");
|
assert_not_reached("Black sheep in the family!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2661,12 +2661,7 @@ int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Finally, compare by contents */
|
/* Finally, compare by contents */
|
||||||
if (af->current_xor_hash < bf->current_xor_hash)
|
return CMP(af->current_xor_hash, bf->current_xor_hash);
|
||||||
return -1;
|
|
||||||
if (af->current_xor_hash > bf->current_xor_hash)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
|
static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
|
||||||
|
|
|
@ -419,12 +419,7 @@ static int exit_prioq_compare(const void *a, const void *b) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Lower priority values first */
|
/* Lower priority values first */
|
||||||
if (x->priority < y->priority)
|
return CMP(x->priority, y->priority);
|
||||||
return -1;
|
|
||||||
if (x->priority > y->priority)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_clock_data(struct clock_data *d) {
|
static void free_clock_data(struct clock_data *d) {
|
||||||
|
@ -1579,12 +1574,7 @@ static int inode_data_compare(const void *a, const void *b) {
|
||||||
if (x->dev > y->dev)
|
if (x->dev > y->dev)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (x->ino < y->ino)
|
return CMP(x->ino, y->ino);
|
||||||
return -1;
|
|
||||||
if (x->ino > y->ino)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inode_data_hash_func(const void *p, struct siphash *state) {
|
static void inode_data_hash_func(const void *p, struct siphash *state) {
|
||||||
|
|
|
@ -101,12 +101,7 @@ static int proposed_rrs_cmp(DnsResourceRecord **x, unsigned x_size, DnsResourceR
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x_size < y_size)
|
return CMP(x_size, y_size);
|
||||||
return -1;
|
|
||||||
if (x_size > y_size)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, DnsResourceRecord ***ret_rrs) {
|
static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, DnsResourceRecord ***ret_rrs) {
|
||||||
|
|
Loading…
Reference in a new issue