提交 3e9158bb 编写于 作者: A Aaron Patterson

do a hash lookup for collision detection

hash lookup should be faster than searching an array.
上级 71fac05c
......@@ -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
......
......@@ -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!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册