Cache stuff in method matcher => ~20% speedup

This commit is contained in:
Markus Schirp 2012-11-22 02:50:55 +01:00
parent a5f387eafd
commit 3c1f5b3831

View file

@ -59,6 +59,14 @@ module Mutant
# #
attr_reader :method_name attr_reader :method_name
def self.cache
@cache ||= {}
end
def self.ast(file)
cache[file] ||= File.read(file).to_ast
end
private private
# Initialize method filter # Initialize method filter
@ -90,7 +98,7 @@ module Mutant
# @api private # @api private
# #
def ast def ast
File.read(source_path).to_ast self.class.ast(source_path)
end end
# Return path to source # Return path to source
@ -112,6 +120,7 @@ module Mutant
def source_line def source_line
source_location.last source_location.last
end end
memoize :source_line
# Return source location # Return source location
# #
@ -122,6 +131,7 @@ module Mutant
def source_location def source_location
method.source_location method.source_location
end end
memoize :source_location
# Return matched node # Return matched node
# #