[hackers] [st][PATCH 3/3] Rearrange run with fast exit

From: Ivan Tham <pickfire_AT_riseup.net>
Date: Mon, 3 Feb 2020 21:05:56 +0800

Quickly swap out of loop to reduce indentation needed.
Reuse deltatime variable to reuse calculation.
---
 x.c | 56 +++++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)
diff --git a/x.c b/x.c
index 76fa689..5f879fa 100644
--- a/x.c
+++ b/x.c
_AT_@ -1928,41 +1928,35 @@ run(void)
 		}
 		deltatime = TIMEDIFF(now, last);
 		if (deltatime > 1000 / (xev ? xfps : actionfps)) {
-			dodraw = 1;
 			last = now;
+			dodraw = 1;
 		}
 
-		if (dodraw) {
-			while (XPending(xw.dpy)) {
-				XNextEvent(xw.dpy, &ev);
-				if (XFilterEvent(&ev, None))
-					continue;
-				if (handler[ev.type])
-					(handler[ev.type])(&ev);
-			}
+		if (!dodraw)
+			continue;
+		while (XPending(xw.dpy)) {
+			XNextEvent(xw.dpy, &ev);
+			if (XFilterEvent(&ev, None))
+				continue;
+			if (handler[ev.type])
+				(handler[ev.type])(&ev);
+		}
 
-			draw();
-			XFlush(xw.dpy);
-
-			if (xev && !FD_ISSET(xfd, &rfd))
-				xev--;
-			if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
-				if (blinkset) {
-					if (TIMEDIFF(now, lastblink) \
-							> blinktimeout) {
-						drawtimeout.tv_nsec = 1000;
-					} else {
-						drawtimeout.tv_nsec = (1E6 * \
-							(blinktimeout - \
-							TIMEDIFF(now,
-								lastblink)));
-					}
-					drawtimeout.tv_sec = \
-					    drawtimeout.tv_nsec / 1E9;
-					drawtimeout.tv_nsec %= (long)1E9;
-				} else {
-					tv = NULL;
-				}
+		draw();
+		XFlush(xw.dpy);
+
+		if (xev && !FD_ISSET(xfd, &rfd))
+			xev--;
+		if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+			if (blinkset) {
+				deltatime = TIMEDIFF(now, lastblink);
+				drawtimeout.tv_nsec = deltatime > blinktimeout
+					? 1000
+					: 1E6 * (blinktimeout - deltatime);
+				drawtimeout.tv_sec = drawtimeout.tv_nsec / 1E9;
+				drawtimeout.tv_nsec %= (long)1E9;
+			} else {
+				tv = NULL;
 			}
 		}
 	}
-- 
2.25.0
Received on Mon Feb 03 2020 - 14:05:56 CET

This archive was generated by hypermail 2.3.0 : Mon Feb 03 2020 - 14:12:27 CET