summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2023-11-15 14:42:02 +0100
committerLuke from DC <[email protected]>2023-11-21 20:19:58 +0000
commitec5938e508526a70962e770ddd811f020951d1e8 (patch)
tree2a4e31654081501fffa3b01d93e80be4e1b1643f
parentf9fb27ba92e61a16a81285aedcfab5d28bd5519e (diff)
downloadmate-panel-ec5938e508526a70962e770ddd811f020951d1e8.tar.bz2
mate-panel-ec5938e508526a70962e770ddd811f020951d1e8.tar.xz
clock: Simplify sort_locations_by_time()
There is no need to return -1 or 1 specifically, anything on the right side of 0 is OK, so simplify using the usual `a - b` implementation for such sort functions. Note that the type is OK here, as the `struct tm` are ints, the same as the function's return value.
-rw-r--r--applets/clock/clock.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 840a45f7..309d4884 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -1187,35 +1187,17 @@ sort_locations_by_time (gconstpointer a, gconstpointer b)
clock_location_localtime (loc_a, &tm_a);
clock_location_localtime (loc_b, &tm_b);
- ret = (tm_a.tm_year == tm_b.tm_year) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_year < tm_b.tm_year) ? -1 : 1;
- }
-
- ret = (tm_a.tm_mon == tm_b.tm_mon) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_mon < tm_b.tm_mon) ? -1 : 1;
- }
-
- ret = (tm_a.tm_mday == tm_b.tm_mday) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_mday < tm_b.tm_mday) ? -1 : 1;
- }
-
- ret = (tm_a.tm_hour == tm_b.tm_hour) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_hour < tm_b.tm_hour) ? -1 : 1;
- }
-
- ret = (tm_a.tm_min == tm_b.tm_min) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_min < tm_b.tm_min) ? -1 : 1;
- }
-
- ret = (tm_a.tm_sec == tm_b.tm_sec) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_sec < tm_b.tm_sec) ? -1 : 1;
- }
+ ret = tm_a.tm_year - tm_b.tm_year;
+ if (! ret)
+ ret = tm_a.tm_mon - tm_b.tm_mon;
+ if (! ret)
+ ret = tm_a.tm_mday - tm_b.tm_mday;
+ if (! ret)
+ ret = tm_a.tm_hour - tm_b.tm_hour;
+ if (! ret)
+ ret = tm_a.tm_min - tm_b.tm_min;
+ if (! ret)
+ ret = tm_a.tm_sec - tm_b.tm_sec;
return ret;
}