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

Introduce new pop_dom_state()

It's basically pop_dom_nodes() without the search part and is now used as a
backend in pop_dom_nodes(). Use it in parse_sgml_document() to avoid two
DOM stack searches in a row.
This commit is contained in:
Jonas Fonseca 2005-12-05 19:40:35 +01:00 committed by Jonas Fonseca
parent 1c4a0d67ce
commit c7ad6f967b
3 changed files with 24 additions and 9 deletions

View File

@ -175,16 +175,28 @@ void
pop_dom_nodes(struct dom_stack *stack, enum dom_node_type type,
unsigned char *string, uint16_t length)
{
struct dom_stack_state *state, *parent;
unsigned int pos;
struct dom_stack_state *state;
if (!dom_stack_has_parents(stack)) return;
parent = search_dom_stack(stack, type, string, length);
if (!parent) return;
state = search_dom_stack(stack, type, string, length);
if (state)
pop_dom_state(stack, type, state);
}
void
pop_dom_state(struct dom_stack *stack, enum dom_node_type type,
struct dom_stack_state *target)
{
struct dom_stack_state *state;
unsigned int pos;
if (!target) return;
if (!dom_stack_has_parents(stack)) return;
foreachback_dom_state (stack, state, pos) {
if (do_pop_dom_node(stack, parent))
if (do_pop_dom_node(stack, target))
break;;
}
}

View File

@ -124,6 +124,11 @@ void pop_dom_node(struct dom_stack *stack);
void pop_dom_nodes(struct dom_stack *stack, enum dom_node_type type,
unsigned char *string, uint16_t length);
/* Pop all stack states until a specific state is reached. */
void
pop_dom_state(struct dom_stack *stack, enum dom_node_type type,
struct dom_stack_state *target);
/* Visit each node in the tree rooted at @root pre-order */
void walk_dom_nodes(struct dom_stack *stack, struct dom_node *root);

View File

@ -255,12 +255,10 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
struct sgml_parser_state *pstate;
pstate = get_dom_stack_state_data(stack, state);
copy_struct(&pstate->end_token, token);
}
pop_dom_nodes(stack, DOM_NODE_ELEMENT,
token->string, token->length);
pop_dom_state(stack, DOM_NODE_ELEMENT, state);
}
}
skip_scanner_token(scanner);
break;