aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-27 22:26:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-27 22:26:34 -0700
commit9d0ca264a028d8fdf6f0c1d38d43db8120b3824d (patch)
tree8397e42938f2252c3e74d0b27875163e2a7f9ed2
parentacb01d68da78506147356fee4a0efbb32a5b9871 (diff)
downloadpw-9d0ca264a028d8fdf6f0c1d38d43db8120b3824d.tar.gz
pw-9d0ca264a028d8fdf6f0c1d38d43db8120b3824d.tar.bz2
pw-9d0ca264a028d8fdf6f0c1d38d43db8120b3824d.zip
Avoid calling poll or gettimeofday for 1000 line bursts.
-rw-r--r--pw.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/pw.c b/pw.c
index 1dc2a40..6ea1407 100644
--- a/pw.c
+++ b/pw.c
@@ -396,7 +396,9 @@ int main(int argc, char **argv)
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
panic("unable to set stdin nonblocking");
- for (unsigned stat = stat_dirty, hpos = 0, kbd_state = kbd_cmd, lasttime = ~0U;
+ for (unsigned stat = stat_dirty, hpos = 0,
+ kbd_state = kbd_cmd, lasttime = ~0U,
+ work = 1000;
kbd_state != kbd_exit ;)
{
int force = 0, nfds = 2, pollms = poll_interval;
@@ -405,24 +407,6 @@ int main(int argc, char **argv)
{ .fd = fd, .events = POLLIN | POLLHUP | POLLERR },
};
- if (stat & stat_trgrd)
- force = 1;
-
- if (!force)
- {
- struct timeval tv;
- unsigned now;
-
- gettimeofday(&tv, NULL);
- now = (((unsigned) tv.tv_sec)%1000000)*1000 + tv.tv_usec/1000;
- if (lasttime == ~0U || now - lasttime > (unsigned) long_interval) {
- if ((stat & stat_dirty) && nlines == maxlines)
- force = 1;
- lasttime = now;
- stat &= ~stat_dirty;
- }
- }
-
if ((stat & stat_eof) == 0) {
int ch;
while ((ch = getc(stdin)) != EOF && ch != '\n')
@@ -470,16 +454,39 @@ int main(int argc, char **argv)
nfds = 1;
}
- if (force) {
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~(stat_dirty | stat_trgrd);
- }
-
if ((stat & stat_eof))
pollms = -1;
else if (nfds < 2)
pollms = 0;
+ if ((stat & (stat_trgrd | stat_susp)) == stat_trgrd)
+ force = 1;
+
+ if (pollms == 0 && !force && work-- > 0)
+ continue;
+
+ work = 1000;
+
+ if (!force)
+ {
+ struct timeval tv;
+ unsigned now;
+
+ gettimeofday(&tv, NULL);
+ now = (((unsigned) tv.tv_sec)%1000000)*1000 + tv.tv_usec/1000;
+ if (lasttime == ~0U || now - lasttime > (unsigned) long_interval) {
+ if ((stat & stat_dirty) && nlines == maxlines)
+ force = 1;
+ lasttime = now;
+ stat &= ~stat_dirty;
+ }
+ }
+
+ if (force) {
+ redraw(circbuf, nlines, hpos, columns, stat, curcmd);
+ stat &= ~(stat_dirty | stat_trgrd);
+ }
+
if (poll(pe, nfds, pollms) <= 0) {
if (pollms) {
if ((stat & stat_dirty) && nlines == maxlines) {