diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-21 14:27:09 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-21 14:27:30 -0700 |
commit | 4d1b3a13129eb7d5fdb1564706acbcd25a5ffa9b (patch) | |
tree | 2f991e9a772cf1fc52273918cd01a1853fafb6c6 | |
parent | 931ee4186b877856b212b0085cd7bd7f6a4aea67 (diff) | |
download | rails-4d1b3a13129eb7d5fdb1564706acbcd25a5ffa9b.tar.gz rails-4d1b3a13129eb7d5fdb1564706acbcd25a5ffa9b.tar.bz2 rails-4d1b3a13129eb7d5fdb1564706acbcd25a5ffa9b.zip |
reuse path formatter from the non-optimized path.
The optimized and non-optimized path share more code now without
significant performance degretation
-rw-r--r-- | actionpack/lib/action_dispatch/journey/route.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/journey/visitors.rb | 31 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 7 |
3 files changed, 3 insertions, 39 deletions
diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index 7e37086da3..cc3c7f20cb 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -76,10 +76,6 @@ module ActionDispatch @path_formatter.evaluate path_options end - def optimized_path - Visitors::OptimizedPath.new.accept(path.spec) - end - def optional_parts path.optional_names.map { |n| n.to_sym } end diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index b635576b6a..52b4c8b489 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -38,7 +38,8 @@ module ActionDispatch @parameters.each do |index| param = parts[index] - value = hash.fetch(param.name) { return ''.freeze } + value = hash[param.name] + return ''.freeze unless value parts[index] = param.escape value end @@ -149,34 +150,6 @@ module ActionDispatch end end - class OptimizedPath < Visitor # :nodoc: - def accept(node) - Array(visit(node)) - end - - private - - def visit_CAT(node) - [visit(node.left), visit(node.right)].flatten - end - - def visit_SYMBOL(node) - node.left[1..-1].to_sym - end - - def visit_STAR(node) - visit(node.left) - end - - def visit_GROUP(node) - [] - end - - %w{ LITERAL SLASH DOT }.each do |t| - class_eval %{ def visit_#{t}(n); n.left; end }, __FILE__, __LINE__ - end - end - class Dot < Visitor # :nodoc: def initialize @nodes = [] diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 72c0aa61ee..31005b2daf 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -168,7 +168,6 @@ module ActionDispatch @klass = Journey::Router::Utils @required_parts = @route.required_parts @arg_size = @required_parts.size - @optimized_path = @route.optimized_path end def call(t, args) @@ -191,11 +190,7 @@ module ActionDispatch raise_generation_error(params, missing_keys) end - @optimized_path.map{ |segment| replace_segment(params, segment) }.join - end - - def replace_segment(params, segment) - Symbol === segment ? @klass.escape_segment(params[segment]) : segment + @route.format params end def optimize_routes_generation?(t) |