[PathList] Use set and intersect to speed up exact matches

parent d60ff0ec
...@@ -128,19 +128,21 @@ module Pod ...@@ -128,19 +128,21 @@ module Pod
else else
full_list = files full_list = files
end end
patterns_array = Array(patterns)
list = Array(patterns).map do |pattern| exact_matches = full_list & patterns_array
patterns_array -= exact_matches
all_patterns = patterns_array.map do |pattern|
if directory?(pattern) && dir_pattern if directory?(pattern) && dir_pattern
pattern += '/' unless pattern.end_with?('/') pattern += '/' unless pattern.end_with?('/')
pattern += dir_pattern pattern += dir_pattern
end end
expanded_patterns = dir_glob_equivalent_patterns(pattern) dir_glob_equivalent_patterns(pattern)
full_list.select do |path|
expanded_patterns.any? do |p|
File.fnmatch(p, path, File::FNM_CASEFOLD | File::FNM_PATHNAME)
end
end
end.flatten end.flatten
list = exact_matches + full_list.select do |path|
all_patterns.any? do |p|
File.fnmatch(p, path, File::FNM_CASEFOLD | File::FNM_PATHNAME)
end
end
list = list.map { |path| Pathname.new(path) } list = list.map { |path| Pathname.new(path) }
if exclude_patterns if exclude_patterns
......
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