Browse files

do a hash lookup for collision detection

hash lookup should be faster than searching an array.
  • Loading branch information...
1 parent 71fac05 commit 3e9158bb95de1770c5a529a903fe15b19a473439 @tenderlove tenderlove committed Jul 31, 2014
View
2 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1765,7 +1765,7 @@ def name_for_action(as, action) #:nodoc:
# 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
View
4 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -140,6 +140,10 @@ def get(name)
routes[name.to_sym]
end
+ def key?(name)
+ routes.key? name.to_sym
+ end
+
alias []= add
alias [] get
alias clear clear!

0 comments on commit 3e9158b

Please sign in to comment.