diff options
author | schneems <richard.schneeman@gmail.com> | 2015-07-25 10:52:11 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2015-07-30 12:31:04 -0500 |
commit | 3fb9e802436a5e3b5733ea9d5cb3964a32a3d8f9 (patch) | |
tree | dd1b2e3341539cad68898d51f09730d424370f0b /actionpack | |
parent | 045cdd3a3d50b06019361cf7bec57f2521facff6 (diff) | |
download | rails-3fb9e802436a5e3b5733ea9d5cb3964a32a3d8f9.tar.gz rails-3fb9e802436a5e3b5733ea9d5cb3964a32a3d8f9.tar.bz2 rails-3fb9e802436a5e3b5733ea9d5cb3964a32a3d8f9.zip |
Only allocate new string when needed
Instead of calling `sub` on every link_to call for controller, we can detect when the string __needs__ to be allocated and only then create a new string (without the leading slash), otherwise, use the string that is given to us.
Saves 888 string objects per request, 35,524 bytes.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 84aeb65007..848b20b054 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -675,7 +675,13 @@ module ActionDispatch # Remove leading slashes from controllers def normalize_controller! - @options[:controller] = controller.sub(%r{^/}, ''.freeze) if controller + if controller + if m = controller.match(/\A\/(?<controller_without_leading_slash>.*)/) + @options[:controller] = m[:controller_without_leading_slash] + else + @options[:controller] = controller + end + end end # Move 'index' action from options to recall |