many: use POINTER_MAY_BE_NULL in inner sort _cmp funcs
Some functions are in the hot path of a sort. While it is more correct to also use assert() here for the passed pointers it is also a runtime cost that should never be needed when e.g. qsort() is used as it will always pass non-NULL pointers. So for these critical functions use POINTER_MAY_BE_NULL() which is compiled out and add a comment to them. Not all _compare() functions are changed, it was a bit of a judgement call because some (like ether_addr_compare) are not called with that much data. But happy to get advise here and tweak accordingly.
This commit is contained in:
@@ -1543,8 +1543,10 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
|
||||
static int table_data_compare(const size_t *a, const size_t *b, Table *t) {
|
||||
int r;
|
||||
|
||||
assert(a);
|
||||
assert(b);
|
||||
/* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we
|
||||
just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */
|
||||
POINTER_MAY_BE_NULL(a);
|
||||
POINTER_MAY_BE_NULL(b);
|
||||
assert(t);
|
||||
assert(t->sort_map);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user