activesupport: Memoize name object allocation in CurrentAttributes.instance
Also, use a symbol key for a faster hash lookup.
This commit is contained in:
parent
6b40767df8
commit
65cd16b541
@ -91,7 +91,7 @@ class CurrentAttributes
|
||||
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 @@ def current_instances
|
||||
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.
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user