* mdocml: Cache the result of uname(3) such that we don't need to call it
@ 2014-01-07 9:10 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-01-07 9:10 UTC (permalink / raw)
To: source
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-01-07 9:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-07 9:10 mdocml: Cache the result of uname(3) such that we don't need to call it schwarze
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).