Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses It is expensive to open and close files for ev...



details:   https://anonhg.NetBSD.org/src/rev/1922837916ce
branches:  trunk
changeset: 348539:1922837916ce
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Oct 23 21:20:56 2016 +0000

description:
It is expensive to open and close files for every printf, keep it around.

diffstat:

 lib/libcurses/curses_private.h |   3 ++-
 lib/libcurses/delwin.c         |   6 ++++--
 lib/libcurses/newwin.c         |   5 +++--
 lib/libcurses/printw.c         |  35 ++++++++++++++++-------------------
 4 files changed, 25 insertions(+), 24 deletions(-)

diffs (149 lines):

diff -r 2d0a335871d2 -r 1922837916ce lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Sun Oct 23 21:01:52 2016 +0000
+++ b/lib/libcurses/curses_private.h    Sun Oct 23 21:20:56 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses_private.h,v 1.50 2014/02/20 09:42:42 blymn Exp $        */
+/*     $NetBSD: curses_private.h,v 1.51 2016/10/23 21:20:56 christos Exp $     */
 
 /*-
  * Copyright (c) 1998-2000 Brett Lymn
@@ -147,6 +147,7 @@
 #ifdef HAVE_WCHAR
        nschar_t *bnsp;                 /* Background non-spacing char list */
 #endif /* HAVE_WCHAR */
+       FILE    *fp;                    /* for window formatted printf */
 };
 
 /* Set of attributes unset by 'me' - 'mb', 'md', 'mh', 'mk', 'mp' and 'mr'. */
diff -r 2d0a335871d2 -r 1922837916ce lib/libcurses/delwin.c
--- a/lib/libcurses/delwin.c    Sun Oct 23 21:01:52 2016 +0000
+++ b/lib/libcurses/delwin.c    Sun Oct 23 21:20:56 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: delwin.c,v 1.18 2013/10/15 22:15:17 roy Exp $  */
+/*     $NetBSD: delwin.c,v 1.19 2016/10/23 21:20:56 christos Exp $     */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)delwin.c   8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: delwin.c,v 1.18 2013/10/15 22:15:17 roy Exp $");
+__RCSID("$NetBSD: delwin.c,v 1.19 2016/10/23 21:20:56 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -112,6 +112,8 @@
                _cursesi_screen->stdscr = NULL;
        if (win == _cursesi_screen->__virtscr)
                _cursesi_screen->__virtscr = NULL;
+       if (win->fp)
+               fclose(win->fp);
        free(win);
        return (OK);
 }
diff -r 2d0a335871d2 -r 1922837916ce lib/libcurses/newwin.c
--- a/lib/libcurses/newwin.c    Sun Oct 23 21:01:52 2016 +0000
+++ b/lib/libcurses/newwin.c    Sun Oct 23 21:20:56 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $  */
+/*     $NetBSD: newwin.c,v 1.48 2016/10/23 21:20:56 christos Exp $     */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)newwin.c   8.3 (Berkeley) 7/27/94";
 #else
-__RCSID("$NetBSD: newwin.c,v 1.47 2009/07/22 16:57:15 roy Exp $");
+__RCSID("$NetBSD: newwin.c,v 1.48 2016/10/23 21:20:56 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -292,6 +292,7 @@
 #ifdef DEBUG
        __CTRACE(__CTRACE_WINDOW, "makenew: win = %p\n", win);
 #endif
+       win->fp = NULL;
 
        /* Set up line pointer array and line space. */
        if ((win->alines = malloc(nlines * sizeof(__LINE *))) == NULL) {
diff -r 2d0a335871d2 -r 1922837916ce lib/libcurses/printw.c
--- a/lib/libcurses/printw.c    Sun Oct 23 21:01:52 2016 +0000
+++ b/lib/libcurses/printw.c    Sun Oct 23 21:20:56 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printw.c,v 1.22 2011/07/17 20:54:34 joerg Exp $        */
+/*     $NetBSD: printw.c,v 1.23 2016/10/23 21:20:56 christos Exp $     */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)printw.c   8.3 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: printw.c,v 1.22 2011/07/17 20:54:34 joerg Exp $");
+__RCSID("$NetBSD: printw.c,v 1.23 2016/10/23 21:20:56 christos Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -47,8 +47,6 @@
  * printw and friends.
  */
 
-static int __winwrite __P((void *, const char *, int));
-
 /*
  * printw --
  *     Printf on the standard screen.
@@ -115,24 +113,21 @@
 /*
  * Internal write-buffer-to-window function.
  */
-static int
-__winwrite(cookie, buf, n)
-       void   *cookie;
-       const char *buf;
-       int     n;
+static ssize_t
+winwrite(void   *cookie, const void *vbuf, size_t n)
 {
        WINDOW *win;
-       int     c;
+       size_t     c;
+       const char *buf = vbuf;
 
-       for (c = n, win = cookie; --c >= 0;)
-       {
+       for (c = 0, win = cookie; c < n; c++) {
 #ifdef DEBUG
                __CTRACE(__CTRACE_MISC, "__winwrite: %c\n", *buf);
 #endif
                if (waddch(win, (chtype) (*buf++ & __CHARTEXT)) == ERR)
                        return (-1);
        }
-       return (n);
+       return (ssize_t)n;
 }
 /*
  * vw_printw --
@@ -141,12 +136,14 @@
 int
 vw_printw(WINDOW *win, const char *fmt, va_list ap)
 {
-       FILE   *f;
-
-       if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL)
-               return (ERR);
-       (void) vfprintf(f, fmt, ap);
-       return (fclose(f) ? ERR : OK);
+       if (win->fp == NULL) {
+               win->fp = funopen2(win, NULL, winwrite, NULL, NULL, NULL);
+               if (win->fp == NULL)
+                       return ERR;
+       }
+       vfprintf(win->fp, fmt, ap);
+       fflush(win->fp);
+       return OK;
 }
 
 __strong_alias(vwprintw, vw_printw)



Home | Main Index | Thread Index | Old Index