* mdocml: Clean up some tight spots in mandoc's default mode:
@ 2010-07-26 21:58 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-07-26 21:58 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mdocml:
term.c
Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.164
retrieving revision 1.165
diff -Lterm.c -Lterm.c -u -p -r1.164 -r1.165
--- term.c
+++ 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
*/
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];
}
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-07-26 21:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-26 21:58 mdocml: Clean up some tight spots in mandoc's default mode: kristaps
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).