From 5d01e23f35ed6a30edc236c88f8aaf652fae8618 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 25 May 2026 20:52:51 +0200 Subject: [PATCH] perf: drop per-parent Selection allocation in getParentsNodes Mirrors #553 for getSiblingNodes, now extended to the ancestor traversal path. --- traversal.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/traversal.go b/traversal.go index c45fa5d..7870f15 100644 --- a/traversal.go +++ b/traversal.go @@ -562,13 +562,12 @@ func findWithMatcher(nodes []*html.Node, m Matcher) []*html.Node { func getParentsNodes(nodes []*html.Node, stopm Matcher, stopNodes []*html.Node) []*html.Node { return mapNodes(nodes, func(i int, n *html.Node) (result []*html.Node) { for p := n.Parent; p != nil; p = p.Parent { - sel := newSingleSelection(p, nil) if stopm != nil { - if sel.IsMatcher(stopm) { + if stopm.Match(p) { break } } else if len(stopNodes) > 0 { - if sel.IsNodes(stopNodes...) { + if isInSlice(stopNodes, p) { break } }