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

10X speed improvements for AS::Dependencies.loadable_constants_for_path #21411

Merged
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
10 changes: 5 additions & 5 deletions activesupport/lib/active_support/dependencies.rb
Expand Up @@ -421,13 +421,13 @@ def loadable_constants_for_path(path, bases = autoload_paths)

bases.each do |root|
expanded_root = File.expand_path(root)
next unless %r{\A#{Regexp.escape(expanded_root)}(/|\\)} =~ expanded_path
next unless expanded_path.start_with?(expanded_root)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the \\ was for Windows support. But then nesting[0] == ?/ was kinda breaking it. Not sure what to do here, but I can test for both.


nesting = expanded_path[(expanded_root.size)..-1]
nesting = nesting[1..-1] if nesting && nesting[0] == ?/
next if nesting.blank?
root_size = expanded_root.size
next if expanded_path[root_size] != ?/.freeze

paths << nesting.camelize
nesting = expanded_path[(root_size + 1)..-1]
paths << nesting.camelize unless nesting.blank?
end

paths.uniq!
Expand Down