diff options
author | eileencodes <eileencodes@gmail.com> | 2015-02-18 18:38:08 -0500 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2015-02-18 18:54:26 -0500 |
commit | e334417b7804b721306e70dbd53d2d542c8f7847 (patch) | |
tree | 617a77b4e01d0873f2af6bc82719f94f8909c4b4 /actionpack/lib/action_dispatch/middleware | |
parent | 83be86933d7faf43ff1717f4258d54fc72d3193c (diff) | |
download | rails-e334417b7804b721306e70dbd53d2d542c8f7847.tar.gz rails-e334417b7804b721306e70dbd53d2d542c8f7847.tar.bz2 rails-e334417b7804b721306e70dbd53d2d542c8f7847.zip |
Reduce the number of times `#clean_path_info` is called
It's unnecessary to call `#clean_path_info`. It doesn't need to be
called on the path with each extension. This reduces allocations to
`Rack::Utils` in integration tests.
Before `#clean_path_info` from `Rack::Utils` (line 622) was number 2
in top 5 allocations:
```
[["rack/lib/rack/utils.rb", 499, :T_STRING], [51034, 4539, 71559, 0, 12, 1791120]]
[["rack/lib/rack/utils.rb", 662, :T_STRING], [33012, 0, 27930, 0, 1, 1226009]]
[["rails/activesupport/lib/active_support/notifications/fanout.rb", 55, :T_DATA], [29998, 0, 25380, 0, 1, 3230600]]
[["rails/activesupport/lib/active_support/subscriber.rb", 99, :T_STRING], [29996, 0, 25378, 0, 2, 1113840]]
[["rails/activesupport/lib/active_support/notifications/instrumenter.rb", 52, :T_HASH], [29994, 147, 27014, 0, 11, 4897784]]
```
After `#clean_path_info` from `Rack::Utils` (line 622) does not appear
in the top 5 highest allocations:
```
[["rack/lib/rack/utils.rb", 499, :T_STRING], [47617, 2414, 68969, 0, 12, 1667360]]
[["rack/lib/rack/body_proxy.rb", 34, :T_ARRAY], [28230, 0, 26060, 0, 1, 1046800]]
[["rails/activesupport/lib/active_support/notifications/fanout.rb", 55, :T_DATA], [28208, 0, 26042, 0, 1, 3034096]]
[["rails/activesupport/lib/active_support/subscriber.rb", 99, :T_STRING], [28204, 0, 26040, 0, 1, 1046080]]
[["rails/activesupport/lib/active_support/callbacks.rb", 165, :T_DATA], [28200, 0, 26046, 0, 2, 3451800]]
```
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/static.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 002bf8b11a..2e1bd45c3d 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -23,10 +23,9 @@ module ActionDispatch def match?(path) path = URI.parser.unescape(path) return false unless path.valid_encoding? + path = Rack::Utils.clean_path_info path - paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"].map { |v| - Rack::Utils.clean_path_info v - } + paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"] if match = paths.detect { |p| path = File.join(@root, p) |