From 24ce22505f53c465459aae9ef86b0d767b2d69e7 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 26 Jul 2010 21:58:41 +0000 Subject: 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. --- term.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'term.c') diff --git a/term.c b/term.c index d212c004..603a6a34 100644 --- a/term.c +++ b/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.164 2010/07/25 22:56:47 kristaps Exp $ */ +/* $Id: term.c,v 1.165 2010/07/26 21:58:41 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -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); @@ -581,18 +580,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]; } } -- cgit v1.2.3