]> git.ipfire.org Git - thirdparty/systemd.git/commit
lldp: simplify compare_func, using ?: to chain comparisons 11140/head
authorFilipe Brandenburger <filbranden@google.com>
Thu, 6 Dec 2018 08:02:51 +0000 (00:02 -0800)
committerFilipe Brandenburger <filbranden@google.com>
Fri, 14 Dec 2018 17:18:42 +0000 (09:18 -0800)
commitdc6bf94d68c38bd20d0abb94a4440441e13eaba3
tree75efc83fd5977290667f29123ca0ae2e904a449c
parentdd102e4d0c6551e9d39c3bdb6715eceea57c8761
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.
src/basic/util.h
src/libsystemd-network/lldp-neighbor.c