aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/class
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-02-04 18:20:04 +0000
committerRick Olson <technoweenie@gmail.com>2007-02-04 18:20:04 +0000
commit334026151581caf90c1ecebec6eec3f466ebc0a7 (patch)
treecdcd6b516f87277e0f322d53f03f430efd6b274d /activesupport/lib/active_support/core_ext/class
parentaa7859c9768f4447b4f67808b2c92f4d0cb48cb2 (diff)
downloadrails-334026151581caf90c1ecebec6eec3f466ebc0a7.tar.gz
rails-334026151581caf90c1ecebec6eec3f466ebc0a7.tar.bz2
rails-334026151581caf90c1ecebec6eec3f466ebc0a7.zip
Optimize Class Inheritable Attributes so that unnecessary hashes are not created. Closes #7472 [Bruce Perens]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6110 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class')
-rw-r--r--activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
index 3c5b2b8340..d8283760b9 100644
--- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -89,10 +89,13 @@ class Class # :nodoc:
end
def inheritable_attributes
- @inheritable_attributes ||= {}
+ @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES
end
def write_inheritable_attribute(key, value)
+ if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
+ inheritable_attributes = {}
+ end
inheritable_attributes[key] = value
end
@@ -111,15 +114,21 @@ class Class # :nodoc:
end
def reset_inheritable_attributes
- inheritable_attributes.clear
+ @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
end
- private
+ private
+ EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze
+
def inherited_with_inheritable_attributes(child)
inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes)
- new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)|
- memo.update(key => (value.dup rescue value))
+ if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
+ new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
+ else
+ new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)|
+ memo.update(key => (value.dup rescue value))
+ end
end
child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)