From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Cache the result of uname(3) such that we don't need to call it
Date: Tue, 7 Jan 2014 04:10:45 -0500 (EST) [thread overview]
Message-ID: <201401070910.s079Aj5t022618@krisdoz.my.domain> (raw)
Log Message:
-----------
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).
Modified Files:
--------------
mdocml:
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.200
retrieving revision 1.201
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.200 -r1.201
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -2348,12 +2348,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;
@@ -2376,39 +2377,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);
- }
- if (strlcat(buf, utsname.release, 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);
}
-#endif /*!OSNAME*/
}
-
- mdoc->meta.os = mandoc_strdup(buf);
+ mdoc->meta.os = mandoc_strdup(defbuf);
+#endif /*!OSNAME*/
return(1);
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-01-07 9:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201401070910.s079Aj5t022618@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).