mirror of
https://github.com/rkd77/elinks.git
synced 2025-04-18 00:47:36 -04: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:
parent
1c4a0d67ce
commit
c7ad6f967b
@ -175,16 +175,28 @@ void
|
|||||||
pop_dom_nodes(struct dom_stack *stack, enum dom_node_type type,
|
pop_dom_nodes(struct dom_stack *stack, enum dom_node_type type,
|
||||||
unsigned char *string, uint16_t length)
|
unsigned char *string, uint16_t length)
|
||||||
{
|
{
|
||||||
struct dom_stack_state *state, *parent;
|
struct dom_stack_state *state;
|
||||||
unsigned int pos;
|
|
||||||
|
|
||||||
if (!dom_stack_has_parents(stack)) return;
|
if (!dom_stack_has_parents(stack)) return;
|
||||||
|
|
||||||
parent = search_dom_stack(stack, type, string, length);
|
state = search_dom_stack(stack, type, string, length);
|
||||||
if (!parent) return;
|
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) {
|
foreachback_dom_state (stack, state, pos) {
|
||||||
if (do_pop_dom_node(stack, parent))
|
if (do_pop_dom_node(stack, target))
|
||||||
break;;
|
break;;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
void pop_dom_nodes(struct dom_stack *stack, enum dom_node_type type,
|
||||||
unsigned char *string, uint16_t length);
|
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 */
|
/* Visit each node in the tree rooted at @root pre-order */
|
||||||
void walk_dom_nodes(struct dom_stack *stack, struct dom_node *root);
|
void walk_dom_nodes(struct dom_stack *stack, struct dom_node *root);
|
||||||
|
|
||||||
|
@ -255,12 +255,10 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
|
|||||||
struct sgml_parser_state *pstate;
|
struct sgml_parser_state *pstate;
|
||||||
|
|
||||||
pstate = get_dom_stack_state_data(stack, state);
|
pstate = get_dom_stack_state_data(stack, state);
|
||||||
|
|
||||||
copy_struct(&pstate->end_token, token);
|
copy_struct(&pstate->end_token, token);
|
||||||
}
|
|
||||||
|
|
||||||
pop_dom_nodes(stack, DOM_NODE_ELEMENT,
|
pop_dom_state(stack, DOM_NODE_ELEMENT, state);
|
||||||
token->string, token->length);
|
}
|
||||||
}
|
}
|
||||||
skip_scanner_token(scanner);
|
skip_scanner_token(scanner);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user