]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use CMP() macros where applicable
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Oct 2018 10:50:43 +0000 (19:50 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 9 Oct 2018 12:45:55 +0000 (14:45 +0200)
src/journal/journald-context.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-netlink/sd-netlink.c

index ce07de1bfba7480a4d1ab6ca491b7d276871ce2b..8037480304c980beadd7addb0dc01f13feeacb36 100644 (file)
 
 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) {
index 3ea71ea13d264eaaacfa740e376f31b3e81a6d27..1437df6cf36ced4a8029343b40680875dcf7982e 100644 (file)
@@ -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(
index 880e127686f37290a4badb8cb66b284328541d7a..720acfb0c79892f864df75d17cefe9a7ecd05b77 100644 (file)
@@ -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) {
index 15830d30c3d713ef6815a2129e790b6d3df8e4db..08b5707351034f780bfe03ed64cc0eab90afc2db 100644 (file)
@@ -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,