From: Yu Watanabe Date: Tue, 9 Oct 2018 10:50:43 +0000 (+0900) Subject: tree-wide: use CMP() macros where applicable X-Git-Tag: v240~599 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c57a73b13a388a132bd5c2170ef806b17601871;p=thirdparty%2Fsystemd.git tree-wide: use CMP() macros where applicable --- diff --git a/src/journal/journald-context.c b/src/journal/journald-context.c index ce07de1bfba..8037480304c 100644 --- a/src/journal/journald-context.c +++ b/src/journal/journald-context.c @@ -62,18 +62,13 @@ static int client_context_compare(const void *a, const void *b) { const ClientContext *x = a, *y = b; + int r; - if (x->timestamp < y->timestamp) - return -1; - if (x->timestamp > y->timestamp) - return 1; - - if (x->pid < y->pid) - return -1; - if (x->pid > y->pid) - return 1; + r = CMP(x->timestamp, y->timestamp); + if (r != 0) + return r; - return 0; + return CMP(x->pid, y->pid); } static int client_context_new(Server *s, pid_t pid, ClientContext **ret) { diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 3ea71ea13d2..1437df6cf36 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1945,13 +1945,7 @@ static int timeout_compare(const void *a, const void *b) { if (x->timeout_usec == 0 && y->timeout_usec != 0) return 1; - if (x->timeout_usec < y->timeout_usec) - return -1; - - if (x->timeout_usec > y->timeout_usec) - return 1; - - return 0; + return CMP(x->timeout_usec, y->timeout_usec); } _public_ int sd_bus_call_async( diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 880e127686f..720acfb0c79 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -314,6 +314,7 @@ static sd_event *event_resolve(sd_event *e) { static int pending_prioq_compare(const void *a, const void *b) { const sd_event_source *x = a, *y = b; + int r; assert(x->pending); assert(y->pending); @@ -325,22 +326,17 @@ static int pending_prioq_compare(const void *a, const void *b) { return 1; /* Lower priority values first */ - if (x->priority < y->priority) - return -1; - if (x->priority > y->priority) - return 1; + r = CMP(x->priority, y->priority); + if (r != 0) + return r; /* Older entries first */ - if (x->pending_iteration < y->pending_iteration) - return -1; - if (x->pending_iteration > y->pending_iteration) - return 1; - - return 0; + return CMP(x->pending_iteration, y->pending_iteration); } static int prepare_prioq_compare(const void *a, const void *b) { const sd_event_source *x = a, *y = b; + int r; assert(x->prepare); assert(y->prepare); @@ -354,18 +350,12 @@ static int prepare_prioq_compare(const void *a, const void *b) { /* Move most recently prepared ones last, so that we can stop * preparing as soon as we hit one that has already been * prepared in the current iteration */ - if (x->prepare_iteration < y->prepare_iteration) - return -1; - if (x->prepare_iteration > y->prepare_iteration) - return 1; + r = CMP(x->prepare_iteration, y->prepare_iteration); + if (r != 0) + return r; /* Lower priority values first */ - if (x->priority < y->priority) - return -1; - if (x->priority > y->priority) - return 1; - - return 0; + return CMP(x->priority, y->priority); } static int earliest_time_prioq_compare(const void *a, const void *b) { @@ -387,12 +377,7 @@ static int earliest_time_prioq_compare(const void *a, const void *b) { return 1; /* Order by time */ - if (x->time.next < y->time.next) - return -1; - if (x->time.next > y->time.next) - return 1; - - return 0; + return CMP(x->time.next, y->time.next); } static usec_t time_event_source_latest(const sd_event_source *s) { @@ -418,12 +403,7 @@ static int latest_time_prioq_compare(const void *a, const void *b) { return 1; /* Order by time */ - if (time_event_source_latest(x) < time_event_source_latest(y)) - return -1; - if (time_event_source_latest(x) > time_event_source_latest(y)) - return 1; - - return 0; + return CMP(time_event_source_latest(x), time_event_source_latest(y)); } static int exit_prioq_compare(const void *a, const void *b) { diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index 15830d30c3d..08b57073510 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -490,13 +490,7 @@ static int timeout_compare(const void *a, const void *b) { if (x->timeout == 0 && y->timeout != 0) return 1; - if (x->timeout < y->timeout) - return -1; - - if (x->timeout > y->timeout) - return 1; - - return 0; + return CMP(x->timeout, y->timeout); } int sd_netlink_call_async(sd_netlink *nl,