diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-05-28 10:12:16 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-05-28 10:17:36 +0200 |
commit | 3cacbc1ef055b3c1702f640969b5840f612b2995 (patch) | |
tree | 8705a06f55f161a6334fe3485c2c05525a6abbba | |
parent | cfd2eff46c90425d96bb912d44d5e290cf523ea6 (diff) | |
download | rails-3cacbc1ef055b3c1702f640969b5840f612b2995.tar.gz rails-3cacbc1ef055b3c1702f640969b5840f612b2995.tar.bz2 rails-3cacbc1ef055b3c1702f640969b5840f612b2995.zip |
Remove double Thread.current storage.
Since we're generating a key through the class name we can combine
the two Thread.current calls into a single hash version.
-rw-r--r-- | activesupport/lib/active_support/current_attributes.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index 9921241c23..837471e97d 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -87,9 +87,7 @@ module ActiveSupport class << self # Returns singleton instance for this class in this thread. If none exists, one is created. def instance - Thread.current[:"current_attributes_for_#{name}"] ||= new.tap do |instance| - current_instances << instance - end + current_instances[name] ||= new end # Declares one or more attributes that will be given both class and instance accessor methods. @@ -125,7 +123,7 @@ module ActiveSupport delegate :set, :reset, to: :instance def reset_all # :nodoc: - current_instances.each(&:reset) + current_instances.each_value(&:reset) end private @@ -134,7 +132,7 @@ module ActiveSupport end def current_instances - Thread.current[:current_attributes_instances] ||= [] + Thread.current[:current_attributes_instances] ||= {} end def method_missing(name, *args, &block) |