avoid redraw when there's no change
authorNRK <nrk@disroot.org>
Fri, 25 Mar 2022 21:51:45 +0000 (22:51 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 25 Mar 2022 21:53:50 +0000 (22:53 +0100)
while i was timing the performance issue, i noticed that there was lots
of random redrawing going on.

turns out there were coming from here; if someone presses CTRL/ALT etc
without pressing anything else, nothing will be inserted, so nothing
will change. but the code will `break`, go down and do a needless redraw.

this patch changes it to simply return if the keypress iscntrl()

also avoid potential UB by casting *buf into an unsigned char.

dmenu.c

diff --git a/dmenu.c b/dmenu.c
index 085dc292631e72778c05c31f4c4840d9ab0b0856..19f6385367133c72bccb2432f549b0a5466497aa 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -415,8 +415,9 @@ keypress(XKeyEvent *ev)
        switch(ksym) {
        default:
 insert:
-               if (!iscntrl(*buf))
-                       insert(buf, len);
+               if (iscntrl((unsigned char)*buf))
+                       return;
+               insert(buf, len);
                break;
        case XK_Delete:
        case XK_KP_Delete: