mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2026-10-21 11:22:48 +00:00
Merge pull request #563 from jvoisin/precise
perf: presize node-set maps in mapNodes, ClosestNodes and winnowNodes
This commit is contained in:
@@ -154,7 +154,7 @@ func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node {
|
||||
return result
|
||||
}
|
||||
|
||||
set := make(map[*html.Node]bool)
|
||||
set := make(map[*html.Node]bool, len(nodes))
|
||||
for _, n := range nodes {
|
||||
set[n] = true
|
||||
}
|
||||
|
||||
+2
-2
@@ -149,7 +149,7 @@ func (s *Selection) ClosestMatcher(m Matcher) *Selection {
|
||||
// ClosestNodes gets the first element that matches one of the nodes by testing the
|
||||
// element itself and traversing up through its ancestors in the DOM tree.
|
||||
func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection {
|
||||
set := make(map[*html.Node]bool)
|
||||
set := make(map[*html.Node]bool, len(nodes))
|
||||
for _, n := range nodes {
|
||||
set[n] = true
|
||||
}
|
||||
@@ -696,7 +696,7 @@ func mapNodes(nodes []*html.Node, f func(int, *html.Node) []*html.Node) (result
|
||||
return f(0, nodes[0])
|
||||
}
|
||||
|
||||
set := make(map[*html.Node]bool)
|
||||
set := make(map[*html.Node]bool, len(nodes))
|
||||
for i, n := range nodes {
|
||||
if vals := f(i, n); len(vals) > 0 {
|
||||
result = appendWithoutDuplicates(result, vals, set)
|
||||
|
||||
Reference in New Issue
Block a user