From 9ec803bb0700a747a32157c78b748349e5763278 Mon Sep 17 00:00:00 2001 From: jasonhl Date: Thu, 9 Apr 2020 21:24:53 -0400 Subject: [PATCH] Reduce calls to get path info when finding routes --- actionpack/lib/action_dispatch/journey/router.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index 31c8d3002f..5679dde71d 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -106,8 +106,9 @@ def filter_routes(path) end def find_routes(req) - routes = filter_routes(req.path_info).concat custom_routes.find_all { |r| - r.path.match?(req.path_info) + path_info = req.path_info + routes = filter_routes(path_info).concat custom_routes.find_all { |r| + r.path.match?(path_info) } if req.head? @@ -119,7 +120,7 @@ def find_routes(req) routes.sort_by!(&:precedence) routes.map! { |r| - match_data = r.path.match(req.path_info) + match_data = r.path.match(path_info) path_parameters = {} match_data.names.each_with_index { |name, i| val = match_data[i + 1] -- GitLab