1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

prepopulate the dispatch cache so we don't need the ThreadSafe cache.

This commit is contained in:
Aaron Patterson 2014-05-20 11:10:52 -07:00
parent e08696421f
commit 74a847771f

View file

@ -1,14 +1,10 @@
# encoding: utf-8 # encoding: utf-8
require 'thread_safe'
module ActionDispatch module ActionDispatch
module Journey # :nodoc: module Journey # :nodoc:
module Visitors # :nodoc: module Visitors # :nodoc:
class Visitor # :nodoc: class Visitor # :nodoc:
DISPATCH_CACHE = ThreadSafe::Cache.new { |h,k| DISPATCH_CACHE = {}
h[k] = :"visit_#{k}"
}
def accept(node) def accept(node)
visit(node) visit(node)
@ -38,8 +34,14 @@ module ActionDispatch
def visit_STAR(n); unary(n); end def visit_STAR(n); unary(n); end
def terminal(node); end def terminal(node); end
%w{ LITERAL SYMBOL SLASH DOT }.each do |t| def visit_LITERAL(n); terminal(n); end
class_eval %{ def visit_#{t}(n); terminal(n); end }, __FILE__, __LINE__ def visit_SYMBOL(n); terminal(n); end
def visit_SLASH(n); terminal(n); end
def visit_DOT(n); terminal(n); end
private_instance_methods(false).each do |pim|
next unless pim =~ /^visit_(.*)$/
DISPATCH_CACHE[$1.to_sym] = pim
end end
end end