source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Another 25% speedup for mandocdb(8) -Q mode, found with
Date: Mon, 6 Jan 2014 16:34:31 -0500 (EST)	[thread overview]
Message-ID: <201401062134.s06LYVXE020802@krisdoz.my.domain> (raw)

Log Message:
-----------
Another 25% speedup for mandocdb(8) -Q mode, found with gprof(1).
For /usr/share/man, we only need 56% of the time of makewhatis(8) now.

In groff, user-defined macros clashing with mdoc(7) or man(7)
standard macros are cleared when parsing the .Dd or .TH macro,
respectively.  Of course, we continue doing that in standard mode 
to assure full groff bug compatibility.

However, in -Q mode, full groff bug compatibility makes no sense
when it's unreasonably expensive, so skip this step in -Q mode.
Real-world manuals hardly ever redefine standard macros, 
that's terrible style, and if they do, it's pointless to do so
before .Dd or .TH because it has no effect.  Even if someone does,
it's extremely unlikely to break mandocdb(8) -Q parsing because we
abort the parse sequence after the NAME section, anyway.

So if you manually redefine .Sh, .Nm, .Nd, or .SH in a way that doesn't 
work at all and rely on .Dd or .TH to fix it up for you, your broken 
manual will no longer get a perfect apropos(1) entry until you re-run
mandocdb(8) without -Q.  It think that consequence is acceptable
in order to get a 25% speedup for everyone else.

Modified Files:
--------------
    mdocml:
        libmandoc.h
        read.c
        roff.c

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -Lroff.c -Lroff.c -u -p -r1.189 -r1.190
--- roff.c
+++ roff.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -109,6 +109,7 @@ struct	roffreg {
 struct	roff {
 	enum mparset	 parsetype; /* requested parse type */
 	struct mparse	*parse; /* parse point */
+	int		 quick; /* skip standard macro deletion */
 	struct roffnode	*last; /* leaf of stack */
 	enum roffrule	 rstack[RSTACK_MAX]; /* stack of !`ie' rules */
 	char		 control; /* control character */
@@ -468,7 +469,7 @@ roff_free(struct roff *r)
 
 
 struct roff *
-roff_alloc(enum mparset type, struct mparse *parse)
+roff_alloc(enum mparset type, struct mparse *parse, int quick)
 {
 	struct roff	*r;
 	int		 i;
@@ -476,6 +477,7 @@ roff_alloc(enum mparset type, struct mpa
 	r = mandoc_calloc(1, sizeof(struct roff));
 	r->parsetype = type;
 	r->parse = parse;
+	r->quick = quick;
 	r->rstackpos = -1;
 	
 	roffhash_init();
@@ -1497,7 +1499,7 @@ roff_Dd(ROFF_ARGS)
 {
 	const char *const	*cp;
 
-	if (MPARSE_MDOC != r->parsetype)
+	if (0 == r->quick && MPARSE_MDOC != r->parsetype)
 		for (cp = __mdoc_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
@@ -1510,7 +1512,7 @@ roff_TH(ROFF_ARGS)
 {
 	const char *const	*cp;
 
-	if (MPARSE_MDOC != r->parsetype)
+	if (0 == r->quick && MPARSE_MDOC != r->parsetype)
 		for (cp = __man_reserved; *cp; cp++)
 			roff_setstr(r, *cp, NULL, 0);
 
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -Lread.c -Lread.c -u -p -r1.42 -r1.43
--- read.c
+++ read.c
@@ -780,7 +780,7 @@ mparse_alloc(enum mparset inttype, enum 
 	curp->defos = defos;
 	curp->quick = quick;
 
-	curp->roff = roff_alloc(inttype, curp);
+	curp->roff = roff_alloc(inttype, curp, curp->quick);
 	return(curp);
 }
 
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.38 -r1.39
--- libmandoc.h
+++ libmandoc.h
@@ -66,7 +66,7 @@ int		 man_addspan(struct man *, const st
 int		 man_addeqn(struct man *, const struct eqn *);
 
 void	 	 roff_free(struct roff *);
-struct roff	*roff_alloc(enum mparset, struct mparse *);
+struct roff	*roff_alloc(enum mparset, struct mparse *, int);
 void		 roff_reset(struct roff *);
 enum rofferr	 roff_parseln(struct roff *, int, 
 			char **, size_t *, int, int *);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-01-06 21:34 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=201401062134.s06LYVXE020802@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).