aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-07-31 11:21:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-07-31 11:22:05 -0700
commit3e9158bb95de1770c5a529a903fe15b19a473439 (patch)
tree76c5729d7183738b295e0e1e6c5a072e487d08d3 /actionpack/lib/action_dispatch
parent71fac05c7402665fb34499447b76b65309a6533a (diff)
downloadrails-3e9158bb95de1770c5a529a903fe15b19a473439.tar.gz
rails-3e9158bb95de1770c5a529a903fe15b19a473439.tar.bz2
rails-3e9158bb95de1770c5a529a903fe15b19a473439.zip
do a hash lookup for collision detection
hash lookup should be faster than searching an array.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 6f7e6f3128..0e8badc498 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1765,7 +1765,7 @@ module ActionDispatch
# and return nil in case it isn't. Otherwise, we pass the invalid name
# forward so the underlying router engine treats it and raises an exception.
if as.nil?
- candidate unless @set.routes.find { |r| r.name == candidate } || candidate !~ /\A[_a-z]/i
+ candidate unless @set.named_routes.key?(candidate) || candidate !~ /\A[_a-z]/i
else
candidate
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 96e23c2464..518d4ca09c 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -140,6 +140,10 @@ module ActionDispatch
routes[name.to_sym]
end
+ def key?(name)
+ routes.key? name.to_sym
+ end
+
alias []= add
alias [] get
alias clear clear!