aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2018-03-20 15:42:31 +0000
committerGitHub <noreply@github.com>2018-03-20 15:42:31 +0000
commit09656debe680ab8b3409b88fc2e7d14cf12ad060 (patch)
tree1bb882b7142e49ac7230f3f5cc4c2c366a6910a5 /actionview
parentc7cbc2e3a074fa22f5ec030f2118dff0c42598ef (diff)
parent05eaa07627376626902bd7acde35406edf1bb2f2 (diff)
downloadrails-09656debe680ab8b3409b88fc2e7d14cf12ad060.tar.gz
rails-09656debe680ab8b3409b88fc2e7d14cf12ad060.tar.bz2
rails-09656debe680ab8b3409b88fc2e7d14cf12ad060.zip
Merge pull request #32305 from q-centrix/perf-improvement-translation-helper
Memoize the result of gsubbing @virtual_path
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