diff --git a/filter.go b/filter.go index 271f050..5fb8a4a 100644 --- a/filter.go +++ b/filter.go @@ -149,7 +149,7 @@ func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node { }) } - set := make(map[*html.Node]bool) + set := make(map[*html.Node]bool, len(nodes)) for _, n := range nodes { set[n] = true } diff --git a/traversal.go b/traversal.go index 46bac05..eb88afb 100644 --- a/traversal.go +++ b/traversal.go @@ -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 } @@ -689,7 +689,7 @@ func getParentNodes(nodes []*html.Node) []*html.Node { // Returns an array of nodes mapped by calling the callback function once for // each node in the source nodes. func mapNodes(nodes []*html.Node, f func(int, *html.Node) []*html.Node) (result []*html.Node) { - 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)