From d7014bc7eaa62c36f045a503cdad64e4ebbc2687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 2 Mar 2012 01:32:08 +0100 Subject: Optimize path helpers. --- actionpack/lib/action_controller/metal/url_for.rb | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'actionpack/lib/action_controller/metal/url_for.rb') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 0b40b1fc4c..4504d9cd10 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -1,7 +1,7 @@ -# Includes +url_for+ into the host class. The class has to provide a +RouteSet+ by implementing +# Includes +url_for+ into the host class. The class has to provide a +RouteSet+ by implementing # the _routes method. Otherwise, an exception will be raised. # -# In addition to AbstractController::UrlFor, this module accesses the HTTP layer to define +# In addition to AbstractController::UrlFor, this module accesses the HTTP layer to define # url options like the +host+. In order to do so, this module requires the host class # to implement +env+ and +request+, which need to be a Rack-compatible. # @@ -18,7 +18,7 @@ # @url = root_path # named route from the application. # end # end -# +# module ActionController module UrlFor extend ActiveSupport::Concern @@ -26,22 +26,20 @@ module ActionController include AbstractController::UrlFor def url_options - @_url_options ||= super.reverse_merge( - :host => request.host, - :port => request.optional_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ).freeze + @_url_options ||= begin + hash = super.reverse_merge( + :host => request.host, + :port => request.optional_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ) - if _routes.equal?(env["action_dispatch.routes"]) - @_url_options.dup.tap do |options| - options[:script_name] = request.script_name.dup - options.freeze + if _routes.equal?(env["action_dispatch.routes"]) + hash[:script_name] = request.script_name.dup end - else - @_url_options + + hash.freeze end end - end end -- cgit v1.2.3