diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-12-21 01:30:59 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-12-21 01:30:59 +0000 |
commit | 924f7087ac0208d0e8ffd68aa9bd2b438dfbbf42 (patch) | |
tree | 30887b304f4cc5ffb2c7719229d9cde94dbac405 | |
parent | 33e7de38cd35cba844b46fb3e0b7075ebfead1c1 (diff) |
Kristaps questioned the efficiency of the algorithm used in roff.c r1.23.
An indeed, this optimization (using suggestions by Joerg Sonnenberger)
saves about 40% of the processing time needed for the roff_res()
function when processing typical manuals.
No functional change, and the new code is not harder to understand.
ok kristaps@
-rw-r--r-- | usr.bin/mandoc/roff.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index a57714bf389..a7337063603 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.23 2010/12/09 20:56:30 schwarze Exp $ */ +/* $Id: roff.c,v 1.24 2010/12/21 01:30:58 schwarze Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -345,18 +345,11 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int pos) size_t nsz; char *n; - /* String escape sequences have at least three characters. */ + /* Search for a leading backslash and save a pointer to it. */ - for (cp = *bufp + pos; cp[0] && cp[1] && cp[2]; cp++) { - - /* - * The first character must be a backslash. - * Save a pointer to it. - */ - - if ('\\' != *cp) - continue; - stesc = cp; + cp = *bufp + pos; + while (NULL != (cp = strchr(cp, '\\'))) { + stesc = cp++; /* * The second character must be an asterisk. @@ -364,7 +357,9 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int pos) * so it can't start another escape sequence. */ - if ('*' != *(++cp)) + if ('\0' == *cp) + return(1); + if ('*' != *cp++) continue; /* @@ -373,7 +368,9 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int pos) * Save a pointer to the name. */ - switch (*(++cp)) { + switch (*cp) { + case ('\0'): + return(1); case ('('): cp++; maxl = 2; |