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

Memoize the result of gsubbing @virtual_path

This gets called many times for each virtual_path, creating a new string
each time that `translate` is called. We can memoize this so that it
only happens once per virtual_path instead.
This commit is contained in:
Dillon Welch 2018-03-19 21:15:16 -07:00
parent 9d9f752661
commit 05eaa07627

View file

@ -122,9 +122,12 @@ module ActionView
private
def scope_key_by_partial(key)
if key.to_s.first == "."
stringified_key = key.to_s
if stringified_key.first == "."
if @virtual_path
@virtual_path.gsub(%r{/_?}, ".") + key.to_s
@_scope_key_by_partial_cache ||= {}
@_scope_key_by_partial_cache[@virtual_path] ||= @virtual_path.gsub(%r{/_?}, ".")
"#{@_scope_key_by_partial_cache[@virtual_path]}#{stringified_key}"
else
raise "Cannot use t(#{key.inspect}) shortcut because path is not available"
end