From: Ralph Corderoy Date: Sun, 13 Aug 2017 15:33:06 +0000 (+0100) Subject: scan(): Don't ioctl(2) for TTY's width every call. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/7d81fd0ae7fc14189d7758c78a5168921c7ef11b?ds=inline scan(): Don't ioctl(2) for TTY's width every call. Saves a system call per message scanned. Does mean it won't adjust should the terminal width change mid scan, but that seems fine; after all, the retrieved width could be out of date by the time a message's output is written anyway. --- diff --git a/uip/scansbr.c b/uip/scansbr.c index df9ef645..24609d26 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -48,6 +48,8 @@ int scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, int unseen, char *folder, long size, int noisy, charstring_t *scanl) { + static bool deja_vu; + static int tty_width; int i, compnum, encrypted, state; char *cp, *tmpbuf, *startbody, **nxtbuf; char *saved_c_text = NULL; @@ -64,9 +66,12 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, scanl used to be a global. */ if (! *scanl) { if (width == -1) { - /* Default: width of the terminal, but at least WIDTH/2. */ - if ((width = sc_width ()) < WIDTH/2) - width = WIDTH/2; + if (!deja_vu) { + deja_vu = true; + tty_width = sc_width(); + } + + width = max(tty_width, WIDTH / 2); } else if (width == 0) { /* Unlimited width. */ width = INT_MAX;