summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-10-09 16:54:34 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-10-09 16:54:34 +0000
commit6e23106b452708f41d0225d8f6c887816d981b05 (patch)
treeb78b002a419f029ecaa27b0bc6d878441f5bfede
parent17cf5fab71df242d839222abbd59d4b728dc8f90 (diff)
downloadnetsurf-6e23106b452708f41d0225d8f6c887816d981b05.tar.gz
netsurf-6e23106b452708f41d0225d8f6c887816d981b05.tar.bz2
Convert more boxes before yielding
svn path=/trunk/netsurf/; revision=13023
-rw-r--r--render/box_construct.c85
1 files changed, 46 insertions, 39 deletions
diff --git a/render/box_construct.c b/render/box_construct.c
index 3d5e91ec3..d00dc41e2 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -258,59 +258,66 @@ static xmlNode *next_node(xmlNode *n, html_content *content,
void convert_xml_to_box(struct box_construct_ctx *ctx)
{
xmlNode *next;
- bool convert_children = true;
+ bool convert_children;
+ uint32_t num_processed = 0;
+ const uint32_t max_processed_before_yield = 10;
- assert(ctx->n != NULL);
- assert(ctx->n->type == XML_ELEMENT_NODE);
+ do {
+ convert_children = true;
- if (box_construct_element(ctx, &convert_children) == false) {
- ctx->cb(ctx->content, false);
- free(ctx);
- return;
- }
+ assert(ctx->n != NULL);
+ assert(ctx->n->type == XML_ELEMENT_NODE);
- /* Find next element to process, converting text nodes as we go */
- next = next_node(ctx->n, ctx->content, convert_children);
- while (next != NULL && next->type != XML_ELEMENT_NODE) {
- if (next->type == XML_TEXT_NODE) {
- ctx->n = next;
- if (box_construct_text(ctx) == false) {
- ctx->cb(ctx->content, false);
- free(ctx);
- return;
+ if (box_construct_element(ctx, &convert_children) == false) {
+ ctx->cb(ctx->content, false);
+ free(ctx);
+ return;
+ }
+
+ /* Find next element to process, converting text nodes as we go */
+ next = next_node(ctx->n, ctx->content, convert_children);
+ while (next != NULL && next->type != XML_ELEMENT_NODE) {
+ if (next->type == XML_TEXT_NODE) {
+ ctx->n = next;
+ if (box_construct_text(ctx) == false) {
+ ctx->cb(ctx->content, false);
+ free(ctx);
+ return;
+ }
}
+
+ next = next_node(next, ctx->content, true);
}
- next = next_node(next, ctx->content, true);
- }
+ ctx->n = next;
- ctx->n = next;
+ if (next == NULL) {
+ /* Conversion complete */
+ struct box root;
- if (next != NULL) {
- /* More work to do: schedule a continuation */
- schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx);
- } else {
- /* Conversion complete */
- struct box root;
+ memset(&root, 0, sizeof(root));
- memset(&root, 0, sizeof(root));
+ root.type = BOX_BLOCK;
+ root.children = root.last = ctx->root_box;
+ root.children->parent = &root;
- root.type = BOX_BLOCK;
- root.children = root.last = ctx->root_box;
- root.children->parent = &root;
+ /** \todo Remove box_normalise_block */
+ if (box_normalise_block(&root, ctx->content) == false) {
+ ctx->cb(ctx->content, false);
+ } else {
+ ctx->content->layout = root.children;
+ ctx->content->layout->parent = NULL;
- /** \todo Remove box_normalise_block */
- if (box_normalise_block(&root, ctx->content) == false) {
- ctx->cb(ctx->content, false);
- } else {
- ctx->content->layout = root.children;
- ctx->content->layout->parent = NULL;
+ ctx->cb(ctx->content, true);
+ }
- ctx->cb(ctx->content, true);
+ free(ctx);
+ return;
}
+ } while (++num_processed < max_processed_before_yield);
- free(ctx);
- }
+ /* More work to do: schedule a continuation */
+ schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx);
}
/**