1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

activesupport: Memoize name object allocation in CurrentAttributes.instance

Also, use a symbol key for a faster hash lookup.
This commit is contained in:
Dylan Thacker-Smith 2019-08-19 13:05:56 -04:00
parent 6b40767df8
commit 65cd16b541

View file

@ -91,7 +91,7 @@ module ActiveSupport
class << self
# Returns singleton instance for this class in this thread. If none exists, one is created.
def instance
current_instances[name] ||= new
current_instances[current_instances_key] ||= new
end
# Declares one or more attributes that will be given both class and instance accessor methods.
@ -150,6 +150,10 @@ module ActiveSupport
Thread.current[:current_attributes_instances] ||= {}
end
def current_instances_key
@current_instances_key ||= name.to_sym
end
def method_missing(name, *args, &block)
# Caches the method definition as a singleton method of the receiver.
#