Cache Node#html? and Node#root_node
The results of these methods is now cached until a Node is moved into another NodeSet. This reduces the time spent in the xpath/evaluator/big_xml_average_bench.rb benchmark from roughly 10 seconds to roughly 5 seconds per iteration.
This commit is contained in:
1 parent
421e6e910b
commit
b0359b37e5
3 files changed
+53
-17
No files matched your search
@@ -144,13 +144,19 @@ describe Oga::XML::Node do
|
||||
@doc = Oga::XML::Document.new(:children => [@n1])
|
||||
end
|
||||
|
||||
it 'returns the root document of an element' do
|
||||
it 'returns the root document of a Node' do
|
||||
@n2.root_node.should == @doc
|
||||
end
|
||||
|
||||
it 'returns the root element of another element' do
|
||||
it 'returns the root Node of another Node' do
|
||||
@n4.root_node.should == @n3
|
||||
end
|
||||
|
||||
it 'flushes the cache when changing the NodeSet of a Node' do
|
||||
@n1.children << @n4
|
||||
|
||||
@n4.root_node.should == @doc
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remove' do
|
||||
@@ -219,6 +225,18 @@ describe Oga::XML::Node do
|
||||
|
||||
node.html?.should == false
|
||||
end
|
||||
|
||||
it 'flushes the cache when changing the NodeSet of a Node' do
|
||||
node = described_class.new
|
||||
html_doc = Oga::XML::Document.new(:type => :html)
|
||||
xml_doc = Oga::XML::Document.new(:type => :xml, :children => [node])
|
||||
|
||||
node.html?.should == false
|
||||
|
||||
html_doc.children << node
|
||||
|
||||
node.html?.should == true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#xml?' do
|
||||
|
||||
Reference in new issue
Block a user