Permalink
Browse files

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.
  • Loading branch information...
1 parent edc0f27 commit 8ee785a17fa0dab88762c2866507bb33760c9f7a @DNNX DNNX committed Jun 20, 2014
Showing with 2 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_dispatch/journey/router.rb
@@ -105,7 +105,8 @@ def find_routes req
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)

0 comments on commit 8ee785a

Please sign in to comment.