From 8e56f5ea3e5394caa2ffee466a7395876c288c2a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 24 Jun 2005 16:40:01 +0000 Subject: Improved performance of Routes generation by a factor of 5 #1434 [Nicholas Seckar] Added named routes (NEEDS BETTER DESCRIPTION) #1434 [Nicholas Seckar] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1496 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/url_rewriter.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_controller/url_rewriter.rb') diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 4313340892..c9fd60880c 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -12,7 +12,7 @@ module ActionController end def to_str - "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@parameters[:controller]}, #{@parameters[:action]}, #{@request.parameters.inspect}" + "#{@request.protocol}, #{@request.host_with_port}, #{@request.path}, #{@parameters[:controller]}, #{@parameters[:action]}, #{@request.parameters.inspect}" end alias_method :to_s, :to_str @@ -28,7 +28,7 @@ module ActionController rewritten_url << '/' if options[:trailing_slash] rewritten_url << "##{options[:anchor]}" if options[:anchor] - return rewritten_url + rewritten_url end def rewrite_path(options) @@ -38,17 +38,16 @@ module ActionController path, extras = Routing::Routes.generate(options, @request) if extras[:overwrite_params] - params_copy = @request.parameters.reject { |k,v| ["controller","action"].include? k } + params_copy = @request.parameters.reject { |k,v| %w(controller action).include? k } params_copy.update extras[:overwrite_params] extras.delete(:overwrite_params) extras.update(params_copy) end - path = "/#{path.join('/')}".chomp '/' - path = '/' if path.empty? - path += build_query_string(extras) + path = "/#{path}" + path << build_query_string(extras) unless extras.empty? - return path + path end # Returns a query string with escaped keys and values from the passed hash. If the passed hash contains an "id" it'll @@ -58,15 +57,14 @@ module ActionController query_string = "" hash.each do |key, value| - key = key.to_s - key = CGI.escape key - key += '[]' if value.class == Array + key = CGI.escape key.to_s + key << '[]' if value.class == Array value = [ value ] unless value.class == Array value.each { |val| elements << "#{key}=#{Routing.extract_parameter_value(val)}" } end query_string << ("?" + elements.join("&")) unless elements.empty? - return query_string + query_string end end end -- cgit v1.2.3