From 769011911ce35ccd504c1c2a7059d0332bd40704 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 26 Apr 2011 15:03:44 +0000 Subject: Optimise first pass of layout. Reduces number of nsfont_width calls by up to the page's word count. svn path=/trunk/netsurf/; revision=12239 --- render/box.h | 3 ++- render/layout.c | 47 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'render') diff --git a/render/box.h b/render/box.h index 7a63203e8..0703c6da5 100644 --- a/render/box.h +++ b/render/box.h @@ -125,7 +125,8 @@ typedef enum { CLONE = 1 << 4, /* continuation of previous box from wrapping */ MEASURED = 1 << 5, /* text box width has been measured */ HAS_HEIGHT = 1 << 6, /* box has height (perhaps due to children) */ - MAKE_HEIGHT = 1 << 7 /* box causes its own height */ + MAKE_HEIGHT = 1 << 7, /* box causes its own height */ + NEED_MIN = 1 << 8 /* minimum width is required for layout */ } box_flags; /* Sides of a box */ diff --git a/render/layout.c b/render/layout.c index 99bdc8b4f..2c97ead0a 100644 --- a/render/layout.c +++ b/render/layout.c @@ -722,6 +722,22 @@ void layout_minmax_block(struct box *block, htype = css_computed_height(block->style, &height, &hunit); } + /* set whether the minimum width is of any interest for this box */ + if (((block->parent && (block->parent->type == BOX_FLOAT_LEFT || + block->parent->type == BOX_FLOAT_RIGHT)) || + block->type == BOX_INLINE_BLOCK) && + wtype != CSS_WIDTH_SET) { + /* box shrinks to fit; need minimum width */ + block->flags |= NEED_MIN; + } else if (block->type == BOX_TABLE_CELL) { + /* box shrinks to fit; need minimum width */ + block->flags |= NEED_MIN; + } else if (block->parent && (block->parent->flags & NEED_MIN) && + wtype != CSS_WIDTH_SET) { + /* box inside shrink-to-fit context; need minimum width */ + block->flags |= NEED_MIN; + } + if (block->gadget && (block->gadget->type == GADGET_TEXTBOX || block->gadget->type == GADGET_PASSWORD || block->gadget->type == GADGET_FILE || @@ -769,6 +785,9 @@ void layout_minmax_block(struct box *block, child_has_height = true; break; case BOX_INLINE_CONTAINER: + if (block->flags & NEED_MIN) + child->flags |= NEED_MIN; + layout_minmax_inline_container(child, &child_has_height, font_func); if (child_has_height && @@ -3068,17 +3087,23 @@ struct box *layout_minmax_line(struct box *first, } /* min = widest word */ - i = 0; - do { - for (j = i; j != b->length && - b->text[j] != ' '; j++) - ; - font_func->font_width(&fstyle, b->text + i, - j - i, &width); - if (min < width) - min = width; - i = j + 1; - } while (j != b->length); + if (b->parent->flags & NEED_MIN) { + /* If we care what the minimum width is, + * calculate it. (It's only needed if we're + * shrinking-to-fit.) */ + i = 0; + do { + for (j = i; j != b->length && + b->text[j] != ' '; j++) + ; + font_func->font_width(&fstyle, + b->text + i, + j - i, &width); + if (min < width) + min = width; + i = j + 1; + } while (j != b->length); + } *line_has_height = true; -- cgit v1.2.3