diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-01-06 23:46:02 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-01-06 23:46:02 +0000 |
commit | e99bbf4b29a4c0d7791f0e51940ef913728e26e4 (patch) | |
tree | b4df6eb950c9e1fca1f76f3be5deb1e7e2ab9226 | |
parent | 9eab414a23b06f9458431484d6516e50ebc74fb0 (diff) |
Gprof(1) is fun. You should use it more often.
Another 10% speedup for mandocdb(8) -Q, and even 3% without -Q.
With -Q, we are now at 41% of the time required by makewhatis(8).
Do not copy predefined strings into the dynamic string table, just
leave them in their own static table and use that one as a fallback
at lookup time. This saves us copying and deleting them for each manual.
No functional change.
-rw-r--r-- | usr.bin/mandoc/roff.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index a767eea6e64..1a92c0f842f 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.63 2014/01/06 21:33:00 schwarze Exp $ */ +/* $Id: roff.c,v 1.64 2014/01/06 23:46:01 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -444,14 +444,9 @@ roff_free1(struct roff *r) void roff_reset(struct roff *r) { - int i; roff_free1(r); - r->control = 0; - - for (i = 0; i < PREDEFS_MAX; i++) - roff_setstr(r, predefs[i].name, predefs[i].str, 0); } @@ -468,7 +463,6 @@ struct roff * roff_alloc(enum mparset type, struct mparse *parse, int quick) { struct roff *r; - int i; r = mandoc_calloc(1, sizeof(struct roff)); r->parsetype = type; @@ -478,9 +472,6 @@ roff_alloc(enum mparset type, struct mparse *parse, int quick) roffhash_init(); - for (i = 0; i < PREDEFS_MAX; i++) - roff_setstr(r, predefs[i].name, predefs[i].str, 0); - return(r); } @@ -1899,12 +1890,18 @@ static const char * roff_getstrn(const struct roff *r, const char *name, size_t len) { const struct roffkv *n; + int i; for (n = r->strtab; n; n = n->next) if (0 == strncmp(name, n->key.p, len) && '\0' == n->key.p[(int)len]) return(n->val.p); + for (i = 0; i < PREDEFS_MAX; i++) + if (0 == strncmp(name, predefs[i].name, len) && + '\0' == predefs[i].name[(int)len]) + return(predefs[i].str); + return(NULL); } |