From 0c4461585dcb41167cad5af5f5b2b3b8905f15d5 Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 6 Jan 2014 21:33:00 +0000 Subject: [PATCH] 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. --- usr.bin/mandoc/libmandoc.h | 4 ++-- usr.bin/mandoc/read.c | 4 ++-- usr.bin/mandoc/roff.c | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 6ca80c1e08a..884a280d9f8 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.24 2014/01/05 20:26:27 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.25 2014/01/06 21:33:00 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2013 Ingo Schwarze @@ -63,7 +63,7 @@ int man_addspan(struct man *, const struct tbl_span *); 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 *); diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index cba3f30bfed..efdb0aa7cab 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.20 2014/01/06 00:53:14 schwarze Exp $ */ +/* $Id: read.c,v 1.21 2014/01/06 21:33:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -755,7 +755,7 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, curp->defos = defos; curp->quick = quick; - curp->roff = roff_alloc(inttype, curp); + curp->roff = roff_alloc(inttype, curp, curp->quick); return(curp); } diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index cf0cf1e8271..a767eea6e64 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,7 +1,7 @@ -/* $Id: roff.c,v 1.62 2013/12/30 18:42:55 schwarze Exp $ */ +/* $Id: roff.c,v 1.63 2014/01/06 21:33:00 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze + * Copyright (c) 2010-2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -105,6 +105,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 */ @@ -464,7 +465,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; @@ -472,6 +473,7 @@ roff_alloc(enum mparset type, struct mparse *parse) r = mandoc_calloc(1, sizeof(struct roff)); r->parsetype = type; r->parse = parse; + r->quick = quick; r->rstackpos = -1; roffhash_init(); @@ -1493,7 +1495,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); @@ -1506,7 +1508,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); -- 2.20.1