From 8e014f28ccd380328f49075b62f23322c49033c2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 10 Aug 2015 12:35:57 -0700 Subject: add a null node at the top of the stack this gives us an easier way to iterate the stack --- actionpack/lib/action_dispatch/routing/mapper.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 928243fc65..9b52598648 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1702,9 +1702,9 @@ module ActionDispatch end def shallow_nesting_depth #:nodoc: - @scope.find_all { |frame| - frame[:scope_level_resource] - }.count { |frame| frame[:scope_level_resource].shallow? } + @scope.find_all { |node| + node.frame[:scope_level_resource] + }.count { |node| node.frame[:scope_level_resource].shallow? } end def param_constraint? #:nodoc: @@ -1974,16 +1974,14 @@ module ActionDispatch self.class.new hash, self, scope_level end + EMPTY_HASH = {}.freeze def new_level(level) - self.class.new(self, self, level) - end - - def fetch(key, &block) - @hash.fetch(key, &block) + self.class.new(EMPTY_HASH, self, level) end def [](key) - @hash.fetch(key) { @parent[key] } + scope = find { |node| node.frame.key? key } + scope && scope.frame[key] end include Enumerable @@ -1992,16 +1990,14 @@ module ActionDispatch node = self loop do break if node.equal? NULL - yield node.frame + yield node node = node.parent end end - protected - def frame; @hash; end - NULL = Scope.new({}.freeze, {}.freeze) + NULL = Scope.new(nil, nil) end def initialize(set) #:nodoc: -- cgit v1.2.3