From d58d8e93fb750be5330739b41dfcce92ab3bc039 Mon Sep 17 00:00:00 2001 From: Samuel Lebeau Date: Tue, 27 Apr 2010 22:45:02 +0200 Subject: [PATCH] Avoid potentially expensive inspect call in router. --- .../lib/action_dispatch/routing/route_set.rb | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index fdbff74..1101b10 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -372,10 +372,9 @@ module ActionDispatch end def generate - error = ActionController::RoutingError.new("No route matches #{options.inspect}") path, params = @set.generate(:path_info, named_route, options, recall, opts) - raise error unless path + raise_routing_error unless path params.reject! {|k,v| !v } @@ -384,7 +383,7 @@ module ActionDispatch path << "?#{params.to_query}" if params.any? "#{script_name}#{path}" rescue Rack::Mount::RoutingError - raise error + raise_routing_error end def opts @@ -404,6 +403,10 @@ module ActionDispatch return false unless current_controller controller.to_param != current_controller.to_param end + + def raise_routing_error + raise ActionController::RoutingError.new("No route matches #{options.inspect}") + end end # Generate the path indicated by the arguments, and return an array of -- 1.6.6