Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions benchmark/xpath.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ prelude: |
xml = '<a>' * DEPTH + '</a>' * DEPTH
doc = REXML::Document.new(xml)

WIDTH = 200
xml_wide = '<root>' + '<child/>' * WIDTH + '</root>'
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
4 changes: 1 addition & 3 deletions lib/rexml/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading