Permalink
Browse files

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

  • Loading branch information...
1 parent e086964 commit 74a847771ff35689ab4a98401ca83e0a0c4b0efa @tenderlove tenderlove committed May 20, 2014
Showing with 9 additions and 7 deletions.
  1. +9 −7 actionpack/lib/action_dispatch/journey/visitors.rb
@@ -1,14 +1,10 @@
# encoding: utf-8
-require 'thread_safe'
-
module ActionDispatch
module Journey # :nodoc:
module Visitors # :nodoc:
class Visitor # :nodoc:
- DISPATCH_CACHE = ThreadSafe::Cache.new { |h,k|
- h[k] = :"visit_#{k}"
- }
+ DISPATCH_CACHE = {}
def accept(node)
visit(node)
@@ -38,8 +34,14 @@ def visit_GROUP(n); unary(n); end
def visit_STAR(n); unary(n); end
def terminal(node); end
- %w{ LITERAL SYMBOL SLASH DOT }.each do |t|
- class_eval %{ def visit_#{t}(n); terminal(n); end }, __FILE__, __LINE__
+ def visit_LITERAL(n); terminal(n); end
+ 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

0 comments on commit 74a8477

Please sign in to comment.