diff --git a/benchmark/xpath.yaml b/benchmark/xpath.yaml index 072e3160..b5cc7739 100644 --- a/benchmark/xpath.yaml +++ b/benchmark/xpath.yaml @@ -28,6 +28,14 @@ prelude: | xml = '' * DEPTH + '' * DEPTH doc = REXML::Document.new(xml) + WIDTH = 200 + xml_wide = '' + '' * WIDTH + '' + doc_wide = REXML::Document.new(xml_wide) + first_child = doc_wide.root.children.first + last_child = doc_wide.root.children.last + benchmark: "REXML::XPath.match(REXML::Document.new(xml), 'a//a')" : REXML::XPath.match(doc, "a//a") "REXML::XPath.match(REXML::Document.new(xml), '//a//a')" : REXML::XPath.match(doc, "//a//a") + "REXML::Document.new(xml_wide).root.children.first.next_sibling_node" : first_child.next_sibling_node + "REXML::Document.new(xml_wide).root.children.last.previous_sibling_node" : last_child.previous_sibling_node diff --git a/lib/rexml/parent.rb b/lib/rexml/parent.rb index 6a53b37a..90004c6b 100644 --- a/lib/rexml/parent.rb +++ b/lib/rexml/parent.rb @@ -121,9 +121,7 @@ def to_a # @return the index of the child, or nil if the object is not a child # of this parent. def index( child ) - count = -1 - @children.find { |i| count += 1 ; i.hash == child.hash } - count + @children.index { |c| c.equal?(child) } end # @return the number of children of this parent