[gs-commits] mupdf 1.16.1.48 Optimise fz_html_box.
[email protected] (Robin Watts) Mon, 30 Sep 2019 15:22:28 +0000 (UTC)
| Newsgroups | gmane.comp.printing.ghostscript.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 980bf8e4f9bb20aa1612c7e568b7c158de7b058b Author: Robin Watts <[email protected]> Date: Fri Sep 27 19:33:02 2019 +0100 Optimise fz_html_box. Only BOX_BLOCK and BOX_TABLE use the padding/margin/border boxes, so only allocate them when needed. diff --git a/source/html/html-imp.h b/source/html/html-imp.h index 212a382..6b347a6 100644 --- a/source/html/html-imp.h +++ b/source/html/html-imp.h @@ -209,9 +209,6 @@ struct fz_html_box_s unsigned int heading : 3; /* h1..h6 */ unsigned int list_item : 23; float x, y, w, b; /* content */ - float padding[4]; - float margin[4]; - float border[4]; float em; /* During construction, 'next' plays double duty; as well * as its normal meaning of 'next sibling', the last sibling @@ -221,6 +218,10 @@ struct fz_html_box_s fz_html_flow *flow_head, **flow_tail; char *id, *href; fz_css_style style; + /* Only BOX_BLOCK and BOX_TABLE actually use the following */ + float padding[4]; + float margin[4]; + float border[4]; }; enum diff --git a/source/html/html-parse.c b/source/html/html-parse.c index c4ab017..686992e 100644 --- a/source/html/html-parse.c +++ b/source/html/html-parse.c @@ -514,6 +514,13 @@ static fz_html_box *new_box(fz_context *ctx, fz_pool *pool, fz_bidi_direction ma return box; } +static fz_html_box *new_short_box(fz_context *ctx, fz_pool *pool, fz_bidi_direction markup_dir) +{ + fz_html_box *box = fz_pool_alloc(ctx, pool, offsetof(fz_html_box, padding)); + init_box(ctx, box, markup_dir); + return box; +} + static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box *top) { box->type = type; @@ -634,7 +641,7 @@ static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *to } else { - fz_html_box *flow = new_box(ctx, g->pool, markup_dir); + fz_html_box *flow = new_short_box(ctx, g->pool, markup_dir); flow->is_first_flow = !top->next; insert_box(ctx, flow, BOX_FLOW, top); insert_box(ctx, box, BOX_INLINE, flow); @@ -682,7 +689,7 @@ generate_boxes(fz_context *ctx, } else { - box = new_box(ctx, g->pool, markup_dir); + box = new_short_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); top = insert_break_box(ctx, box, top); } @@ -697,7 +704,7 @@ generate_boxes(fz_context *ctx, int w, h; const char *w_att = fz_xml_att(node, "width"); const char *h_att = fz_xml_att(node, "height"); - box = new_box(ctx, g->pool, markup_dir); + box = new_short_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); if (w_att && (w = fz_atoi(w_att)) > 0) { @@ -716,7 +723,7 @@ generate_boxes(fz_context *ctx, else if (tag[0]=='s' && tag[1]=='v' && tag[2]=='g' && tag[3]==0) { - box = new_box(ctx, g->pool, markup_dir); + box = new_short_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); insert_inline_box(ctx, box, top, markup_dir, g); generate_image(ctx, box, load_svg_image(ctx, g->zip, g->base_uri, node), g); @@ -736,14 +743,14 @@ generate_boxes(fz_context *ctx, box = new_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); top = insert_block_box(ctx, box, top); - imgbox = new_box(ctx, g->pool, markup_dir); + imgbox = new_short_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &imgbox->style, &match); insert_inline_box(ctx, imgbox, box, markup_dir, g); generate_image(ctx, imgbox, fz_keep_image(ctx, img), g); } else if (display == DIS_INLINE) { - box = new_box(ctx, g->pool, markup_dir); + box = new_short_box(ctx, g->pool, markup_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); insert_inline_box(ctx, box, top, markup_dir, g); generate_image(ctx, box, fz_keep_image(ctx, img), g); @@ -774,7 +781,10 @@ generate_boxes(fz_context *ctx, if (lang) child_lang = fz_text_language_from_string(lang); - box = new_box(ctx, g->pool, child_dir); + if (display == DIS_INLINE) + box = new_short_box(ctx, g->pool, child_dir); + else + box = new_box(ctx, g->pool, child_dir); fz_apply_css_style(ctx, g->set, &box->style, &match); id = fz_xml_att(node, "id"); @@ -872,7 +882,7 @@ generate_boxes(fz_context *ctx, if (top->type != BOX_INLINE) { /* Create anonymous inline box, with the same style as the top block box. */ - box = new_box(ctx, g->pool, markup_dir); + box = new_short_box(ctx, g->pool, markup_dir); insert_inline_box(ctx, box, top, markup_dir, g); box->style = top->style; /* Make sure not to recursively multiply font sizes. */ http://git.ghostscript.com/?p=mupdf.git;a=commit;h=980bf8e4f9bb20aa1612c7e568b7c158de7b058b -- MuPDF library Artifex Software, Inc.