Skip to content

Commit 8f5a6ff

Browse files
authored
Reduce memory allocations in querySelector resolution (#17821)
These memory allocations at the entry don't need to happen because they're live for the entire evaluation.
1 parent e928487 commit 8f5a6ff

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

ext/dom/lexbor/lexbor/selectors-adapted/selectors.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,14 @@ lxb_selectors_find(lxb_selectors_t *selectors, const xmlNode *root,
338338
const lxb_css_selector_list_t *list,
339339
lxb_selectors_cb_f cb, void *ctx)
340340
{
341-
lxb_selectors_entry_t *entry;
341+
lxb_selectors_entry_t entry = {0};
342342
lxb_selectors_nested_t nested;
343343

344-
entry = lexbor_dobject_calloc(selectors->objs);
345-
346-
entry->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE;
347-
entry->selector = list->last;
344+
entry.combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE;
345+
entry.selector = list->last;
348346

349347
nested.parent = NULL;
350-
nested.entry = entry;
348+
nested.entry = &entry;
351349
nested.cb = cb;
352350
nested.ctx = ctx;
353351

@@ -363,20 +361,19 @@ lxb_selectors_match_node(lxb_selectors_t *selectors, const xmlNode *node,
363361
lxb_selectors_cb_f cb, void *ctx)
364362
{
365363
lxb_status_t status;
366-
lxb_selectors_entry_t *entry;
367364
lxb_selectors_nested_t nested;
368365

369366
if (!CMP_NODE_TYPE(node, XML_ELEMENT_NODE)) {
370367
return LXB_STATUS_OK;
371368
}
372369

373-
entry = lexbor_dobject_calloc(selectors->objs);
370+
lxb_selectors_entry_t entry = {0};
374371

375-
entry->combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE;
376-
entry->selector = list->last;
372+
entry.combinator = LXB_CSS_SELECTOR_COMBINATOR_CLOSE;
373+
entry.selector = list->last;
377374

378375
nested.parent = NULL;
379-
nested.entry = entry;
376+
nested.entry = &entry;
380377
nested.cb = cb;
381378
nested.ctx = ctx;
382379

0 commit comments

Comments
 (0)