1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

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 <fonseca@diku.dk>
This commit is contained in:
Jonas Fonseca 2005-12-08 03:02:27 +01:00 committed by Jonas Fonseca
parent 8f97dc8403
commit 4480a9a4cd
3 changed files with 11 additions and 3 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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) {