aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies
diff options
context:
space:
mode:
authorPan Thomakos <pan.thomakos@gmail.com>2012-03-11 23:18:03 -0700
committerPan Thomakos <pan.thomakos@gmail.com>2012-03-11 23:26:48 -0700
commit6b480d2e8260b88474a33f1b45847e0ad8b1bc96 (patch)
treebb484e7384f3dc5c228e3859e7d4878540365ae6 /activesupport/lib/active_support/dependencies
parent6c0d5a19a4e97be3d004997f6547ec19e6a22363 (diff)
downloadrails-6b480d2e8260b88474a33f1b45847e0ad8b1bc96.tar.gz
rails-6b480d2e8260b88474a33f1b45847e0ad8b1bc96.tar.bz2
rails-6b480d2e8260b88474a33f1b45847e0ad8b1bc96.zip
Improved ActiveSupport::Autoload performance.
`ActiveSupport::Autoload#autoload` performance is improved in the default case where a path is present. Since the full path name is not generated, it isn't necessary to determine the full constant name either. This results in a 3x performance gain and reduces the number of Ruby objects generated. For a full benchmark check [this gist](https://gist.github.com/2020228).
Diffstat (limited to 'activesupport/lib/active_support/dependencies')
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index 4c771da096..a1626ebeba 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -9,13 +9,16 @@ module ActiveSupport
@@eager_autoload = false
def autoload(const_name, path = @@at_path)
- full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
- location = path || Inflector.underscore(full)
+ unless path
+ full = [name, @@under_path, const_name.to_s, path].compact.join("::")
+ path = Inflector.underscore(full)
+ end
if @@eager_autoload
- @@autoloads[const_name] = location
+ @@autoloads[const_name] = path
end
- super const_name, location
+
+ super const_name, path
end
def autoload_under(path)