diff options
author | Viktar Basharymau <viktar.basharymau@thehamon.com> | 2014-06-20 17:16:11 +0300 |
---|---|---|
committer | Viktar Basharymau <viktar.basharymau@thehamon.com> | 2014-06-20 17:16:11 +0300 |
commit | 8ee785a17fa0dab88762c2866507bb33760c9f7a (patch) | |
tree | be28b2eb9aff2461da0b1158d0dbce09ffb2f1c2 /actionpack/lib/action_dispatch/journey | |
parent | edc0f271978585635153068c708d62f5243dafe0 (diff) | |
download | rails-8ee785a17fa0dab88762c2866507bb33760c9f7a.tar.gz rails-8ee785a17fa0dab88762c2866507bb33760c9f7a.tar.bz2 rails-8ee785a17fa0dab88762c2866507bb33760c9f7a.zip |
Replace x.sort_by!.select! with x.select!.sort_by!
The latter has the same speed as the former in the worst case
and faster in general, because it is always better to sort less items.
Unfortunately, `routes.select!{...}.sort_by!{...}` is not possible here
because `select!` returns `nil`, so select! and sort! must be done
in two steps.
Diffstat (limited to 'actionpack/lib/action_dispatch/journey')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/router.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index fe3fc0a9fa..21817b374c 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -105,7 +105,8 @@ module ActionDispatch routes.concat get_routes_as_head(routes) end - routes.sort_by!(&:precedence).select! { |r| r.matches?(req) } + routes.select! { |r| r.matches?(req) } + routes.sort_by!(&:precedence) routes.map! { |r| match_data = r.path.match(req.path_info) |