From: schwarze Date: Tue, 7 Jan 2014 09:10:58 +0000 (+0000) Subject: Cache the result of uname(3) such that we don't need to call it X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4c4681288c7fbdcbfecdcc1851ecdd6d7bb5e797;p=openbsd Cache the result of uname(3) such that we don't need to call it over and over again for each manual; found with gprof(1). Speeds up mandocdb(8) -Q by 3%, now at 39.5% of makewhatis(8). --- diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index ec94325f88c..b744882e788 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.118 2014/01/06 22:39:19 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.119 2014/01/07 09:10:58 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -2344,12 +2344,13 @@ post_bx(POST_ARGS) static int post_os(POST_ARGS) { - struct mdoc_node *n; char buf[BUFSIZ]; - int c; #ifndef OSNAME struct utsname utsname; + static char *defbuf; #endif + struct mdoc_node *n; + int c; n = mdoc->last; @@ -2372,39 +2373,31 @@ post_os(POST_ARGS) assert(c); - if ('\0' == buf[0]) { - if (mdoc->defos) { - mdoc->meta.os = mandoc_strdup(mdoc->defos); - return(1); - } + if ('\0' != *buf) { + mdoc->meta.os = mandoc_strdup(buf); + return(1); + } + + if (mdoc->defos) { + mdoc->meta.os = mandoc_strdup(mdoc->defos); + return(1); + } + #ifdef OSNAME - if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) { - mdoc_nmsg(mdoc, n, MANDOCERR_MEM); - return(0); - } + mdoc->meta.os = mandoc_strdup(OSNAME); #else /*!OSNAME */ + if (NULL == defbuf) { if (-1 == uname(&utsname)) { mdoc_nmsg(mdoc, n, MANDOCERR_UNAME); - mdoc->meta.os = mandoc_strdup("UNKNOWN"); - return(post_prol(mdoc)); - } - - if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) { - mdoc_nmsg(mdoc, n, MANDOCERR_MEM); - return(0); - } - if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) { - mdoc_nmsg(mdoc, n, MANDOCERR_MEM); - return(0); + defbuf = mandoc_strdup("UNKNOWN"); + } else if (-1 == asprintf(&defbuf, "%s %s", + utsname.sysname, utsname.release)) { + perror(NULL); + exit((int)MANDOCLEVEL_SYSERR); } - if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) { - mdoc_nmsg(mdoc, n, MANDOCERR_MEM); - return(0); - } -#endif /*!OSNAME*/ } - - mdoc->meta.os = mandoc_strdup(buf); + mdoc->meta.os = mandoc_strdup(defbuf); +#endif /*!OSNAME*/ return(1); }