diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-09-22 12:39:41 -0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-09-22 12:39:41 -0700 |
commit | 7dcde9fba4928eb68a5f6be7173af29ba775401c (patch) | |
tree | 18492af15237ce8a62d31ec98a9a2815e9e2ac23 /actionpack | |
parent | ffc8abd41b420c2eac58fe92fb03e494e690e43f (diff) | |
parent | 5c224de9e110763ec7a0f01f5b604bcf81f40bfb (diff) | |
download | rails-7dcde9fba4928eb68a5f6be7173af29ba775401c.tar.gz rails-7dcde9fba4928eb68a5f6be7173af29ba775401c.tar.bz2 rails-7dcde9fba4928eb68a5f6be7173af29ba775401c.zip |
Merge pull request #9155 from bogdan/route-formatter
Rewrite Journey::Visitors::Formatter for performance
Diffstat (limited to 'actionpack')
-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 |