lldp: simplify compare_func, using ?: to chain comparisons
The ?: operator is very useful for chaining comparison functions (strcmp, memcmp, CMP), since its behavior is to return the result of the comparison function call if non-zero, or continue evaluating the chain of comparison functions. This simplifies the code in that using a temporary `r` variable to store the function results is no longer necessary and the checks for non-zero to return are no longer needed either, resulting in a typical three-fold reduction to the number of lines in the code. Introduce a new memcmp_nn() to compare two memory buffers in lexicographic order, taking length in consideration. Tested: $ ninja -C build/ test All test cases pass. In particular, test_multiple_neighbors_sorted() in test-lldp would catch regressions introduced by this commit.
Loading
Please register or sign in to comment