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