perf: drop per-parent Selection allocation in getParentsNodes

Mirrors #553 for getSiblingNodes, now extended to the ancestor traversal path.
This commit is contained in:
jvoisin
2026-05-25 20:52:51 +02:00
parent 83a0a8bbd8
commit 5d01e23f35
+2 -3
View File
@@ -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
}
}