提交 3fb9e802 编写于 作者: S schneems

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.
上级 045cdd3a
......@@ -675,7 +675,13 @@ def use_relative_controller!
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册