From 3fb9e802436a5e3b5733ea9d5cb3964a32a3d8f9 Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 25 Jul 2015 10:52:11 -0500 Subject: 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. --- actionpack/lib/action_dispatch/routing/route_set.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_dispatch/routing') 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\/(?.*)/) + @options[:controller] = m[:controller_without_leading_slash] + else + @options[:controller] = controller + end + end end # Move 'index' action from options to recall -- cgit v1.2.3