From 3cacbc1ef055b3c1702f640969b5840f612b2995 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 28 May 2017 10:12:16 +0200 Subject: 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. --- activesupport/lib/active_support/current_attributes.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/current_attributes.rb') 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) -- cgit v1.2.3