aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorDillon Welch <daw0328@gmail.com>2018-03-19 21:15:16 -0700
committerDillon Welch <daw0328@gmail.com>2018-03-20 07:26:14 -0700
commit05eaa07627376626902bd7acde35406edf1bb2f2 (patch)
tree35365537628cc273a0db0bdf7a5b960bf263688c /actionview
parent9d9f752661c31b3063d55bec14e797c957d2bb7d (diff)
downloadrails-05eaa07627376626902bd7acde35406edf1bb2f2.tar.gz
rails-05eaa07627376626902bd7acde35406edf1bb2f2.tar.bz2
rails-05eaa07627376626902bd7acde35406edf1bb2f2.zip
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.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/translation_helper.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb
index 1860bc4732..80cb73d683 100644
--- a/actionview/lib/action_view/helpers/translation_helper.rb
+++ b/actionview/lib/action_view/helpers/translation_helper.rb
@@ -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