aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2010-09-27 14:48:06 +0200
committerthedarkone <thedarkone2@gmail.com>2010-09-27 17:45:58 +0200
commit5a518487fe66b11b81e21dc6c31d036057a410ed (patch)
tree8b3cbece8b7af5b56d214c5e0bc19a8a6eeb4d02 /activesupport/lib
parent8cda132136a766621b4c976cb1df7007d12ee6b5 (diff)
downloadrails-5a518487fe66b11b81e21dc6c31d036057a410ed.tar.gz
rails-5a518487fe66b11b81e21dc6c31d036057a410ed.tar.bz2
rails-5a518487fe66b11b81e21dc6c31d036057a410ed.zip
Try to use Hash's native #[] for speed.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/configurable.rb2
-rw-r--r--activesupport/lib/active_support/ordered_options.rb8
2 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb
index 3d91560833..1914f10669 100644
--- a/activesupport/lib/active_support/configurable.rb
+++ b/activesupport/lib/active_support/configurable.rb
@@ -18,7 +18,7 @@ module ActiveSupport
def self.crystalize!(keys)
keys.each do |key|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def #{key}; self[#{key.inspect}]; end
+ def #{key}; _get(#{key.inspect}); end
RUBY
end
end
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index 99c6c5a0c0..124e1a74f8 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -18,6 +18,9 @@ require 'active_support/ordered_hash'
#
module ActiveSupport #:nodoc:
class OrderedOptions < OrderedHash
+ alias_method :_get, :[] # preserve the original #[] method
+ protected :_get # make it protected
+
def []=(key, value)
super(key.to_sym, value)
end
@@ -37,7 +40,10 @@ module ActiveSupport #:nodoc:
class InheritableOptions < OrderedOptions
def initialize(parent = nil)
- if parent
+ if parent.kind_of?(OrderedOptions)
+ # use the faster _get when dealing with OrderedOptions
+ super() { |h,k| parent._get(k) }
+ elsif parent
super() { |h,k| parent[k] }
else
super()