diff options
author | schneems <richard.schneeman+foo@gmail.com> | 2018-08-29 09:44:15 -0500 |
---|---|---|
committer | schneems <richard.schneeman+foo@gmail.com> | 2018-08-29 09:49:24 -0500 |
commit | e92adb3da6fef3388cc79abb03bf751baac8b2f0 (patch) | |
tree | 352cb074288094b273bb820cf3b839ae364bce18 | |
parent | 068fe7dc9045856b822833db5cb7cb690e6000d7 (diff) | |
download | rails-e92adb3da6fef3388cc79abb03bf751baac8b2f0.tar.gz rails-e92adb3da6fef3388cc79abb03bf751baac8b2f0.tar.bz2 rails-e92adb3da6fef3388cc79abb03bf751baac8b2f0.zip |
Fewer allocations in caching/fragments.rb
Instead of using a splat on the head and tail we can mutate the array by flattening 1 level. We get further savings by not allocating another via `compact` but instead by using `compact!`
-rw-r--r-- | actionpack/lib/abstract_controller/caching/fragments.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/abstract_controller/caching/fragments.rb b/actionpack/lib/abstract_controller/caching/fragments.rb index febd8a67a6..95078a2a28 100644 --- a/actionpack/lib/abstract_controller/caching/fragments.rb +++ b/actionpack/lib/abstract_controller/caching/fragments.rb @@ -88,7 +88,11 @@ module AbstractController def combined_fragment_cache_key(key) head = self.class.fragment_cache_keys.map { |k| instance_exec(&k) } tail = key.is_a?(Hash) ? url_for(key).split("://").last : key - [ :views, (ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"]), *head, *tail ].compact + + cache_key = [:views, ENV["RAILS_CACHE_ID"] || ENV["RAILS_APP_VERSION"], head, tail] + cache_key.flatten!(1) + cache_key.compact! + cache_key end # Writes +content+ to the location signified by |