From 4480a9a4cd26ae0d1b4ec28e670593a0827c9d95 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 8 Dec 2005 03:02:27 +0100 Subject: [PATCH] Removes node from the DOM tree when using the SGML stream parser That should free up some short-term memory. Signed-off-by: Jonas Fonseca --- src/document/dom/stack.c | 6 +++++- src/document/dom/stack.h | 5 ++++- src/document/sgml/parser.c | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/document/dom/stack.c b/src/document/dom/stack.c index d1dc11a65..e760a88f4 100644 --- a/src/document/dom/stack.c +++ b/src/document/dom/stack.c @@ -48,7 +48,7 @@ void init_dom_stack(struct dom_stack *stack, void *parser, void *renderer, dom_stack_callback_T push_callbacks[DOM_NODES], dom_stack_callback_T pop_callbacks[DOM_NODES], - size_t object_size) + size_t object_size, int keep_nodes) { assert(stack); @@ -57,6 +57,7 @@ init_dom_stack(struct dom_stack *stack, void *parser, void *renderer, stack->parser = parser; stack->renderer = renderer; stack->object_size = object_size; + stack->keep_nodes = !!keep_nodes; if (push_callbacks) memcpy(stack->push_callbacks, push_callbacks, DOM_STACK_CALLBACKS_SIZE); @@ -148,6 +149,9 @@ do_pop_dom_node(struct dom_stack *stack, struct dom_stack_state *parent) callback(stack, state->node, state_data); } + if (!stack->keep_nodes) + done_dom_node(state->node); + stack->depth--; assert(stack->depth >= 0); diff --git a/src/document/dom/stack.h b/src/document/dom/stack.h index b3d603ad5..15c55e1f5 100644 --- a/src/document/dom/stack.h +++ b/src/document/dom/stack.h @@ -37,6 +37,9 @@ struct dom_stack { struct dom_stack_state *states; size_t depth; + /* Keep nodes when popping them or call done_dom_node() on them. */ + unsigned int keep_nodes:1; + /* This is one big array of parser specific objects. */ /* The objects hold parser specific data. For the SGML parser this * holds DTD-oriented info about the node (recorded in struct @@ -110,7 +113,7 @@ search_dom_stack(struct dom_stack *stack, enum dom_node_type type, void init_dom_stack(struct dom_stack *stack, void *parser, void *renderer, dom_stack_callback_T push_callbacks[DOM_NODES], dom_stack_callback_T pop_callbacks[DOM_NODES], - size_t object_size); + size_t object_size, int keep_nodes); void done_dom_stack(struct dom_stack *stack); /* Decends down to the given node making it the current parent */ diff --git a/src/document/sgml/parser.c b/src/document/sgml/parser.c index c65b36751..f28ccfa79 100644 --- a/src/document/sgml/parser.c +++ b/src/document/sgml/parser.c @@ -318,7 +318,8 @@ init_sgml_parser(enum sgml_parser_type type, void *renderer, struct uri *uri, parser->info = &sgml_html_info; init_dom_stack(&parser->stack, parser, renderer, - push_callbacks, pop_callbacks, obj_size); + push_callbacks, pop_callbacks, obj_size, + type != SGML_PARSER_STREAM); parser->root = add_sgml_document(&parser->stack, parser->uri); if (!parser->root) {