Skip to content

Commit

Permalink
Merge pull request #1297 from bruno-/xml_node_ancestors
Browse files Browse the repository at this point in the history
XML::Node#ancestors optimization
  • Loading branch information
larskanis committed Jan 6, 2016
2 parents 912dcb4 + 11ac451 commit 2ccfd2f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,10 @@ def ancestors selector = nil
return NodeSet.new(document, parents) unless selector

root = parents.last
search_results = root.search(selector)

NodeSet.new(document, parents.find_all { |parent|
root.search(selector).include?(parent)
search_results.include?(parent)
})
end

Expand Down

0 comments on commit 2ccfd2f

Please sign in to comment.