Skip to content

Commit

Permalink
Avoid using Pathname on Resolver and AS::Dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 23, 2010
1 parent 6f83a50 commit 69abbe8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/template/resolver.rb
Expand Up @@ -99,7 +99,7 @@ class FileSystemResolver < PathResolver
def initialize(path)
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
super()
@path = Pathname.new(path).expand_path
@path = File.expand_path(path)
end

def eql?(resolver)
Expand Down
21 changes: 15 additions & 6 deletions activesupport/lib/active_support/dependencies.rb
Expand Up @@ -353,14 +353,23 @@ def local_const_defined?(mod, const) #:nodoc:
# Given +path+, a filesystem path to a ruby file, return an array of constant
# paths which would cause Dependencies to attempt to load this file.
def loadable_constants_for_path(path, bases = autoload_paths)
expanded_path = Pathname.new(path[/\A(.*?)(\.rb)?\Z/, 1]).expand_path
path = $1 if path =~ /\A(.*)\.rb\Z/
expanded_path = File.expand_path(path)
paths = []

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

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

bases.inject([]) do |paths, root|
expanded_root = Pathname.new(root).expand_path
nesting = expanded_path.relative_path_from(expanded_root).to_s
next paths if nesting =~ /\.\./
paths << nesting.camelize
end.uniq
end

paths.uniq!
paths
end

# Search for a file in autoload_paths matching the provided suffix.
Expand Down

4 comments on commit 69abbe8

@neerajsingh0101
Copy link

Choose a reason for hiding this comment

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

any particular reason for not using Pathname

@josevalim
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Terribly slow. If you want an alternative implementation: http://github.com/stouset/pathname3

@josevalim
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This commit yielded a 50% speed improvement in development for a mid-sized Rails app.

@neerajsingh0101
Copy link

Choose a reason for hiding this comment

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

that's a big gain for a relatively small line of code change

Please sign in to comment.