Removed the XPath::Evaluator class

This commit is contained in:
Yorick Peterse 2015-08-30 01:25:54 +02:00
parent e4919d7c31
commit 31a574e7f8
9 changed files with 3 additions and 1844 deletions

View File

@ -28,12 +28,13 @@ require 'profile' if ENV['PROFILE']
thread_count.times.each do thread_count.times.each do
threads << Thread.new do threads << Thread.new do
oga_doc = documents.pop oga_doc = documents.pop
evaluator = Oga::XPath::Evaluator.new(oga_doc) compiler = Oga::XPath::Compiler.new
block = compiler.compile(xpath_ast)
sample_size.times do sample_size.times do
break if stop break if stop
output << Benchmark.measure { evaluator.evaluate_ast(xpath_ast) } output << Benchmark.measure { block.call(oga_doc) }
end end
end end
end end

View File

@ -1,30 +0,0 @@
require_relative '../../benchmark_helper'
xml_node = Oga::XML::Element.new(:name => 'foo')
name_only = AST::Node.new(:test, [nil, 'foo'])
name_star = AST::Node.new(:test, [nil, '*'])
name_ns_star = AST::Node.new(:test, ['*', 'foo'])
name_ns = AST::Node.new(:test, ['bar', 'foo'])
evaluator = Oga::XPath::Evaluator.new(xml_node)
Benchmark.ips do |bench|
bench.report 'name only' do
evaluator.node_matches?(xml_node, name_only)
end
bench.report 'name wildcard' do
evaluator.node_matches?(xml_node, name_star)
end
bench.report 'name + namespace' do
evaluator.node_matches?(xml_node, name_ns)
end
bench.report 'namespace wildcard' do
evaluator.node_matches?(xml_node, name_ns_star)
end
bench.compare!
end

View File

@ -14,9 +14,6 @@ rex_doc = REXML::Document.new(xml)
ox_exp = 'number/^Text' ox_exp = 'number/^Text'
xpath_exp = 'root/number/text()' xpath_exp = 'root/number/text()'
oga_ast = Oga::XPath::Parser.new(xpath_exp).parse
evaluator = Oga::XPath::Evaluator.new(oga_doc)
Benchmark.ips do |bench| Benchmark.ips do |bench|
# Technically not XPath but it's the closest thing Ox provides. # Technically not XPath but it's the closest thing Ox provides.
bench.report 'Ox' do bench.report 'Ox' do
@ -31,12 +28,6 @@ Benchmark.ips do |bench|
oga_doc.xpath(xpath_exp) oga_doc.xpath(xpath_exp)
end end
# This is measured to see what the performance of the evaluator is _without_
# the overhead of the lexer/parser.
bench.report 'Oga cached' do
evaluator.evaluate_ast(oga_ast)
end
bench.report 'REXML' do bench.report 'REXML' do
REXML::XPath.match(rex_doc, xpath_exp) REXML::XPath.match(rex_doc, xpath_exp)
end end

View File

@ -55,7 +55,6 @@ require 'oga/ruby/generator'
require 'oga/xpath/lexer' require 'oga/xpath/lexer'
require 'oga/xpath/parser' require 'oga/xpath/parser'
require 'oga/xpath/evaluator'
require 'oga/xpath/compiler' require 'oga/xpath/compiler'
require 'oga/xpath/conversion' require 'oga/xpath/conversion'

View File

@ -10,7 +10,6 @@ module Oga
# #
# @param [String] expression The XPath expression to run. # @param [String] expression The XPath expression to run.
# @param [Hash] variables Variables to bind. # @param [Hash] variables Variables to bind.
# @see [Oga::XPath::Evaluator#initialize]
# #
def xpath(expression, variables = {}) def xpath(expression, variables = {})
ast = XPath::Parser.parse_with_cache(expression) ast = XPath::Parser.parse_with_cache(expression)
@ -35,7 +34,6 @@ module Oga
# Evaluates the given CSS expression. # Evaluates the given CSS expression.
# #
# @param [String] expression The CSS expression to run. # @param [String] expression The CSS expression to run.
# @see [Oga::XPath::Evaluator#initialize]
# #
def css(expression) def css(expression)
ast = CSS::Parser.parse_with_cache(expression) ast = CSS::Parser.parse_with_cache(expression)

File diff suppressed because it is too large Load Diff