diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-02 06:56:40 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-02 06:56:40 -0800 |
commit | 1a046ab9bf7f0c3fa045a2b771a5a22d318f02ff (patch) | |
tree | f3694b72ccc15888a9c32910b1dc92a42a6f762e /actionpack/lib/action_dispatch/routing/url_for.rb | |
parent | aeeebe1fdca56d20a9950f5585d10f8089388278 (diff) | |
parent | cd5dabab95924dfaf3af8c429454f1a46d9665c1 (diff) | |
download | rails-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_dispatch/routing/url_for.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/url_for.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index ee6616c5d3..94db36ce1f 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -102,6 +102,9 @@ module ActionDispatch super end + # Hook overriden in controller to add request information + # with `default_url_options`. Application logic should not + # go into url_options. def url_options default_url_options end @@ -152,6 +155,11 @@ module ActionDispatch protected + def optimize_routes_generation? + return @_optimized_routes if defined?(@_optimized_routes) + @_optimized_routes = _routes.optimize_routes_generation? && default_url_options.empty? + end + def _with_routes(routes) old_routes, @_routes = @_routes, routes yield |