diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2013-08-28 11:13:11 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2013-08-28 11:13:11 +0300 |
commit | 5c224de9e110763ec7a0f01f5b604bcf81f40bfb (patch) | |
tree | 6a4cb624233c687d5dc11040e0b0c5edabec9a57 /actionpack/lib/action_dispatch/journey | |
parent | af3a69a783ea810d0045a6106f6c59573984f2ff (diff) | |
download | rails-5c224de9e110763ec7a0f01f5b604bcf81f40bfb.tar.gz rails-5c224de9e110763ec7a0f01f5b604bcf81f40bfb.tar.bz2 rails-5c224de9e110763ec7a0f01f5b604bcf81f40bfb.zip |
Rewrite journey routes formatter for performance
Diffstat (limited to 'actionpack/lib/action_dispatch/journey')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/visitors.rb | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 0a8cb1b4d4..1fea8344e7 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -84,44 +84,44 @@ module ActionDispatch # Used for formatting urls (url_for) class Formatter < Visitor # :nodoc: - attr_reader :options, :consumed + attr_reader :options def initialize(options) @options = options - @consumed = {} end private - def visit_GROUP(node) - if consumed == options - nil - else - route = visit(node.left) - route.include?("\0") ? nil : route + def visit(node, optional = false) + case node.type + when :LITERAL, :SLASH, :DOT + node.left + when :STAR + visit(node.left) + when :GROUP + visit(node.left, true) + when :CAT + visit_CAT(node, optional) + when :SYMBOL + visit_SYMBOL(node) end end - def terminal(node) - node.left - end - - def binary(node) - [visit(node.left), visit(node.right)].join - end - - def nary(node) - node.children.map { |c| visit(c) }.join + def visit_CAT(node, optional) + left = visit(node.left, optional) + right = visit(node.right, optional) + if optional && !(right && left) + "" + else + left + right + end end def visit_SYMBOL(node) - key = node.to_sym - - if value = options[key] - consumed[key] = value + if value = options[node.to_sym] Router::Utils.escape_path(value) else - "\0" + nil end end end |