Krolyxon
Commit 633a4f6

Branches

Refs →

nsxiv633a4f6

check_timeouts: avoid unnecessary conversions (#273)

before we were using select, which expected `struct timeval` as
arg. so we needed to do ms -> timeval conversions.

but now since we're using poll, which accepts milisec as arg, there's
no need to do ms -> timeval -> ms. instead have check_timeouts directly
return ms.
Author
N-R-K
Date
2022-05-12 14:47 +0000
Committer
GitHub · 2022-05-12 14:47 +0000
Parent
3a22e6a
Commit
633a4f66d98e46755effb71d6cd3f8a681c4818c

+4 −10

2 files changed

  1. M main.c +4 −4
  2. M nsxiv.h +0 −6
M main.c View
@@ -207,7 +207,7 @@ void reset_timeout(timeout_f handler)
207207 }
208208 }
209209
210−static bool check_timeouts(struct timeval *t)
210+static bool check_timeouts(int *t)
211211 {
212212 int i = 0, tdiff, tmin = -1;
213213 struct timeval now;
@@ -228,7 +228,7 @@ static bool check_timeouts(struct timeval *t)
228228 i++;
229229 }
230230 if (tmin > 0 && t != NULL)
231− TV_SET_MSEC(t, tmin);
231+ *t = tmin;
232232 return tmin > 0;
233233 }
234234
@@ -703,7 +703,7 @@ static void run(void)
703703 {
704704 enum { FD_X, FD_INFO, FD_ARL, FD_CNT };
705705 struct pollfd pfd[FD_CNT];
706− struct timeval timeout = {0};
706+ int timeout = 0;
707707 const struct timespec ten_ms = {0, 10000000};
708708 bool discard, init_thumb, load_thumb, to_set;
709709 XEvent ev, nextev;
@@ -735,7 +735,7 @@ static void run(void)
735735 pfd[FD_ARL].fd = arl.fd;
736736 pfd[FD_X].events = pfd[FD_INFO].events = pfd[FD_ARL].events = POLLIN;
737737
738− if (poll(pfd, ARRLEN(pfd), to_set ? TV_TO_MS(&timeout) : -1) < 0)
738+ if (poll(pfd, ARRLEN(pfd), to_set ? timeout : -1) < 0)
739739 continue;
740740 if (pfd[FD_INFO].revents & POLLIN)
741741 read_info();
M nsxiv.h View
@@ -44,12 +44,6 @@
4444
4545 #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
4646 ((t1)->tv_usec - (t2)->tv_usec) / 1000)
47−#define TV_TO_MS(tv) (((tv)->tv_sec * 1000) + ((tv)->tv_usec / 1000))
48−
49−#define TV_SET_MSEC(tv,t) { \
50− (tv)->tv_sec = (t) / 1000; \
51− (tv)->tv_usec = (t) % 1000 * 1000; \
52−}
5347
5448 #define TV_ADD_MSEC(tv,t) { \
5549 (tv)->tv_sec += (t) / 1000; \