* mdocml: Cache column sizes and char pointer into mdoc_bl.
@ 2010-07-04 21:59 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-07-04 21:59 UTC (permalink / raw)
To: source
Log Message:
-----------
Cache column sizes and char pointer into mdoc_bl. Finally get rid of
the loops here and there to track down the MDOC_Column arguments.
Modified Files:
--------------
mdocml:
mdoc.h
mdoc_action.c
mdoc_html.c
mdoc_term.c
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.108 -r1.109
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -647,8 +647,16 @@ pre_bl(PRE_ARGS)
/* Assign list type. */
- if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE)
+ if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE) {
n->data.Bl->type = lt;
+ /* Set column information, too. */
+ if (LIST_column == lt) {
+ n->data.Bl->ncols =
+ n->args->argv[i].sz;
+ n->data.Bl->cols = (const char **)
+ n->args->argv[i].value;
+ }
+ }
/* The list type should come first. */
@@ -1150,14 +1158,8 @@ post_it(POST_ARGS)
return(0);
break;
case (LIST_column):
- cols = -1;
- for (i = 0; i < (int)n->args->argc; i++)
- if (MDOC_Column == n->args->argv[i].arg) {
- cols = (int)n->args->argv[i].sz;
- break;
- }
+ cols = (int)n->data.Bl->ncols;
- assert(-1 != cols);
assert(NULL == mdoc->last->head->child);
if (NULL == mdoc->last->body->child)
@@ -1197,12 +1199,7 @@ post_bl_head(POST_ARGS)
n = mdoc->last->parent;
if (LIST_column == n->data.Bl->type) {
- for (i = 0; i < (int)n->args->argc; i++)
- if (MDOC_Column == n->args->argv[i].arg)
- break;
- assert(i < (int)n->args->argc);
-
- if (n->args->argv[i].sz && mdoc->last->nchild) {
+ if (n->data.Bl->ncols && mdoc->last->nchild) {
mdoc_nmsg(mdoc, n, MANDOCERR_COLUMNS);
return(0);
}
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.92 -r1.93
--- mdoc_html.c
+++ mdoc_html.c
@@ -1074,7 +1074,7 @@ mdoc_it_head_pre(MDOC_ARGS, enum mdoc_li
static int
mdoc_it_pre(MDOC_ARGS)
{
- int i, wp, comp;
+ int i, comp;
const struct mdoc_node *bl, *nn;
struct roffsu width, offs;
enum mdoc_list type;
@@ -1116,16 +1116,6 @@ mdoc_it_pre(MDOC_ARGS)
if (bl->data.Bl->width)
a2width(bl->data.Bl->width, &width);
- wp = -1;
- for (i = 0; bl->args && i < (int)bl->args->argc; i++)
- switch (bl->args->argv[i].arg) {
- case (MDOC_Column):
- wp = i; /* Save for later. */
- break;
- default:
- break;
- }
-
/* Override width in some cases. */
switch (type) {
@@ -1149,8 +1139,8 @@ mdoc_it_pre(MDOC_ARGS)
for (i = 0; nn && nn != n; nn = nn->next)
if (MDOC_BODY == nn->type)
i++;
- if (i < (int)bl->args->argv[wp].sz)
- a2width(bl->args->argv[wp].value[i], &width);
+ if (i < (int)bl->data.Bl->ncols)
+ a2width(bl->data.Bl->cols[i], &width);
}
if (MDOC_HEAD == n->type)
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.74 -r1.75
--- mdoc_action.c
+++ mdoc_action.c
@@ -782,6 +782,9 @@ post_bl_head(POST_ARGS)
np->args->argv[c].value = mandoc_malloc
((size_t)n->nchild * sizeof(char *));
+ n->data.Bl->ncols = np->args->argv[c].sz;
+ n->data.Bl->cols = (const char **)np->args->argv[c].value;
+
for (i = 0, nn = n->child; nn; i++) {
np->args->argv[c].value[i] = nn->string;
nn->string = NULL;
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.169
retrieving revision 1.170
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.169 -r1.170
--- mdoc_term.c
+++ mdoc_term.c
@@ -57,7 +57,6 @@ static size_t a2width(const struct ter
static size_t a2height(const struct termp *, const char *);
static size_t a2offs(const struct termp *, const char *);
-static int arg_getattr(int, const struct mdoc_node *);
static void print_bvspace(struct termp *,
const struct mdoc_node *,
const struct mdoc_node *);
@@ -527,26 +526,6 @@ a2offs(const struct termp *p, const char
/*
- * Get the index of an argument in a node's argument list or -1 if it
- * does not exist.
- */
-static int
-arg_getattr(int v, const struct mdoc_node *n)
-{
- int i;
-
- if (NULL == n->args)
- return(0);
-
- for (i = 0; i < (int)n->args->argc; i++)
- if (n->args->argv[i].arg == v)
- return(i);
-
- return(-1);
-}
-
-
-/*
* Determine how much space to print out before block elements of `It'
* (and thus `Bl') and `Bd'. And then go ahead and print that space,
* too.
@@ -631,7 +610,7 @@ termp_it_pre(DECL_ARGS)
{
const struct mdoc_node *bl, *nn;
char buf[7];
- int i, col;
+ int i;
size_t width, offset, ncols, dcol;
enum mdoc_list type;
@@ -660,8 +639,6 @@ termp_it_pre(DECL_ARGS)
if (MDOC_HEAD == n->type)
break;
- col = arg_getattr(MDOC_Column, bl);
-
/*
* Imitate groff's column handling:
* - For each earlier column, add its width.
@@ -671,7 +648,8 @@ termp_it_pre(DECL_ARGS)
* column.
* - For more than 5 columns, add only one column.
*/
- ncols = bl->args->argv[col].sz;
+ ncols = bl->data.Bl->ncols;
+
/* LINTED */
dcol = ncols < 5 ? term_len(p, 4) :
ncols == 5 ? term_len(p, 3) : term_len(p, 1);
@@ -685,7 +663,7 @@ termp_it_pre(DECL_ARGS)
nn->prev && i < (int)ncols;
nn = nn->prev, i++)
offset += dcol + a2width
- (p, bl->args->argv[col].value[i]);
+ (p, bl->data.Bl->cols[i]);
/*
* When exceeding the declared number of columns, leave
@@ -700,7 +678,7 @@ termp_it_pre(DECL_ARGS)
* Use the declared column widths, extended as explained
* in the preceding paragraph.
*/
- width = a2width(p, bl->args->argv[col].value[i]) + dcol;
+ width = a2width(p, bl->data.Bl->cols[i]) + dcol;
break;
default:
if (NULL == bl->data.Bl->width)
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.99
retrieving revision 1.100
diff -Lmdoc.h -Lmdoc.h -u -p -r1.99 -r1.100
--- mdoc.h
+++ mdoc.h
@@ -303,6 +303,8 @@ struct mdoc_bl {
const char *offs; /* -offset */
enum mdoc_list type; /* -tag, -enum, etc. */
int comp; /* -compact */
+ size_t ncols; /* -column arg count */
+ const char **cols; /* -column val ptr */
};
struct mdoc_bf {
--
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-04 21:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-04 21:59 mdocml: Cache column sizes and char pointer into mdoc_bl 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).