Commit ae94566f authored by Vincent Isambart's avatar Vincent Isambart

Move caching from FileAccessor to PathList

parent 9e0b0762
...@@ -39,7 +39,6 @@ module Pod ...@@ -39,7 +39,6 @@ module Pod
@path_list = PathList.new(path_list) @path_list = PathList.new(path_list)
end end
@spec_consumer = spec_consumer @spec_consumer = spec_consumer
@paths_for_attribute = { false => {}, true => {} }
unless @spec_consumer unless @spec_consumer
raise Informative, 'Attempt to initialize File Accessor without a specification consumer.' raise Informative, 'Attempt to initialize File Accessor without a specification consumer.'
...@@ -277,14 +276,13 @@ module Pod ...@@ -277,14 +276,13 @@ module Pod
# @return [Array<Pathname>] the paths. # @return [Array<Pathname>] the paths.
# #
def paths_for_attribute(attribute, include_dirs = false) def paths_for_attribute(attribute, include_dirs = false)
return @paths_for_attribute[include_dirs][attribute] if @paths_for_attribute[include_dirs][attribute]
file_patterns = spec_consumer.send(attribute) file_patterns = spec_consumer.send(attribute)
options = { options = {
:exclude_patterns => spec_consumer.exclude_files, :exclude_patterns => spec_consumer.exclude_files,
:dir_pattern => GLOB_PATTERNS[attribute], :dir_pattern => GLOB_PATTERNS[attribute],
:include_dirs => include_dirs, :include_dirs => include_dirs,
} }
@paths_for_attribute[include_dirs][attribute] = expanded_paths(file_patterns, options) expanded_paths(file_patterns, options)
end end
# Matches the given patterns to the file present in the root of the path # Matches the given patterns to the file present in the root of the path
......
...@@ -21,6 +21,7 @@ module Pod ...@@ -21,6 +21,7 @@ module Pod
# #
def initialize(root) def initialize(root)
@root = root @root = root
@glob_cache = {}
end end
# @return [Array<String>] The list of absolute the path of all the files # @return [Array<String>] The list of absolute the path of all the files
...@@ -46,6 +47,7 @@ module Pod ...@@ -46,6 +47,7 @@ module Pod
unless root.exist? unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`." raise Informative, "Attempt to read non existent folder `#{root}`."
end end
@glob_cache = {}
root_length = root.to_s.length + 1 root_length = root.to_s.length + 1
escaped_root = escape_path_for_glob(root) escaped_root = escape_path_for_glob(root)
paths = Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH) paths = Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH)
...@@ -101,6 +103,10 @@ module Pod ...@@ -101,6 +103,10 @@ module Pod
def relative_glob(patterns, options = {}) def relative_glob(patterns, options = {})
return [] if patterns.empty? return [] if patterns.empty?
cache_key = options.merge(:patterns => patterns)
cached_value = @glob_cache[cache_key]
return cached_value if cached_value
dir_pattern = options[:dir_pattern] dir_pattern = options[:dir_pattern]
exclude_patterns = options[:exclude_patterns] exclude_patterns = options[:exclude_patterns]
include_dirs = options[:include_dirs] include_dirs = options[:include_dirs]
...@@ -133,7 +139,7 @@ module Pod ...@@ -133,7 +139,7 @@ module Pod
exclude_options = { :dir_pattern => '**/*', :include_dirs => include_dirs } exclude_options = { :dir_pattern => '**/*', :include_dirs => include_dirs }
list -= relative_glob(exclude_patterns, exclude_options) list -= relative_glob(exclude_patterns, exclude_options)
end end
list @glob_cache[cache_key] = list
end end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment