Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[path_list.rb] Improve performance of read_file_system #5927

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Enhancements

* Improve performance of PathList.read_file_system
[Heath Borders](https://github.com/hborders)
[#5890](https://github.com/CocoaPods/CocoaPods/issues/5890)

* Cache result of uses_swift and should_build to speed up pod install.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#5837](https://github.com/CocoaPods/CocoaPods/pull/5837)
Expand Down
19 changes: 15 additions & 4 deletions lib/cocoapods/sandbox/path_list.rb
Expand Up @@ -51,11 +51,22 @@ def read_file_system
raise Informative, "Attempt to read non existent folder `#{root}`."
end
escaped_root = escape_path_for_glob(root)
absolute_paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH)

absolute_paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH).lazy
dirs_and_files = absolute_paths.reject { |path| path.basename.to_s =~ /^\.\.?$/ }
relative_paths = dirs_and_files.map { |path| path.relative_path_from(root) }
sorted_paths = relative_paths.map(&:to_s).sort_by(&:upcase)
@dirs, @files = sorted_paths.partition { |path| File.directory?(root + path) }
dirs, files = dirs_and_files.partition { |path| File.directory?(path) }

root_length = root.cleanpath.to_s.length + File::SEPARATOR.length
sorted_relative_paths_from_full_paths = lambda do |paths|
relative_paths = paths.lazy.map do |path|
path_string = path.to_s
path_string.slice(root_length, path_string.length - root_length)
end
relative_paths.sort_by(&:upcase)
end

@dirs = sorted_relative_paths_from_full_paths.call(dirs)
@files = sorted_relative_paths_from_full_paths.call(files)
@glob_cache = {}
end

Expand Down