summaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-26 21:58:41 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-26 21:58:41 +0000
commit1fd005d98a28db7342389bec4f417e3fa20edd5d (patch)
treef8107c078024785b62f6aa035ab27d5f9b471ee7 /term.c
parent7a3400728abf2d32ac0c2a420dfd3eb2af8a53f7 (diff)
downloadmandoc-1fd005d98a28db7342389bec4f417e3fa20edd5d.tar.gz
Clean up some tight spots in mandoc's default mode: pessimistically
pre-allocate the output buffer for words and in-line the buffera() function, which was only called in one place anyway.
Diffstat (limited to 'term.c')
-rw-r--r--term.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/term.c b/term.c
index 8af60c41..24fc0114 100644
--- a/term.c
+++ b/term.c
@@ -37,7 +37,6 @@
static void spec(struct termp *, enum roffdeco,
const char *, size_t);
static void res(struct termp *, const char *, size_t);
-static void buffera(struct termp *, const char *, size_t);
static void bufferc(struct termp *, char);
static void adjbuf(struct termp *p, size_t);
static void encode(struct termp *, const char *, size_t);
@@ -582,18 +581,6 @@ adjbuf(struct termp *p, size_t sz)
static void
-buffera(struct termp *p, const char *word, size_t sz)
-{
-
- if (p->col + sz >= p->maxcols)
- adjbuf(p, p->col + sz);
-
- memcpy(&p->buf[(int)p->col], word, sz);
- p->col += sz;
-}
-
-
-static void
bufferc(struct termp *p, char c)
{
@@ -617,23 +604,31 @@ encode(struct termp *p, const char *word, size_t sz)
*/
if (TERMFONT_NONE == (f = term_fonttop(p))) {
- buffera(p, word, sz);
+ if (p->col + sz >= p->maxcols)
+ adjbuf(p, p->col + sz);
+ memcpy(&p->buf[(int)p->col], word, sz);
+ p->col += sz;
return;
}
+ /* Pre-buffer, assuming worst-case. */
+
+ if (p->col + 1 + (sz * 3) >= p->maxcols)
+ adjbuf(p, p->col + 1 + (sz * 3));
+
for (i = 0; i < (int)sz; i++) {
if ( ! isgraph((u_char)word[i])) {
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = word[i];
continue;
}
if (TERMFONT_UNDER == f)
- bufferc(p, '_');
+ p->buf[(int)p->col++] = '_';
else
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = word[i];
- bufferc(p, 8);
- bufferc(p, word[i]);
+ p->buf[(int)p->col++] = 8;
+ p->buf[(int)p->col++] = word[i];
}
}