aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/url_for.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-02 06:56:40 -0800
committerJosé Valim <jose.valim@gmail.com>2012-03-02 06:56:40 -0800
commit1a046ab9bf7f0c3fa045a2b771a5a22d318f02ff (patch)
treef3694b72ccc15888a9c32910b1dc92a42a6f762e /actionpack/lib/action_controller/metal/url_for.rb
parentaeeebe1fdca56d20a9950f5585d10f8089388278 (diff)
parentcd5dabab95924dfaf3af8c429454f1a46d9665c1 (diff)
downloadrails-1a046ab9bf7f0c3fa045a2b771a5a22d318f02ff.tar.gz
rails-1a046ab9bf7f0c3fa045a2b771a5a22d318f02ff.tar.bz2
rails-1a046ab9bf7f0c3fa045a2b771a5a22d318f02ff.zip
Merge pull request #5242 from rails/opt_routes
Optimize routes generation in simple cases. If you pass to the route helper the same amount of arguments as the required segments, route generation will be optimized as a string interpolation. After this commit, `post_path(post)` is about 6.5 times faster, `post_url(post)` is about 5 times.
Diffstat (limited to 'actionpack/lib/action_controller/metal/url_for.rb')
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb30
1 files changed, 14 insertions, 16 deletions
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 <tt>_routes</tt> method. Otherwise, an exception will be raised.
#
-# In addition to <tt>AbstractController::UrlFor</tt>, this module accesses the HTTP layer to define
+# In addition to <tt>AbstractController::UrlFor</tt>, 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