From d04bcf94da9a19d9470f920587f8d2055d3b7108 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Apr 2014 15:50:58 -0700 Subject: only ask if `t` is empty once. --- actionpack/lib/action_dispatch/journey/gtg/transition_table.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index e6212b1ee2..53c47f4696 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -40,6 +40,7 @@ module ActionDispatch end def move(t, a) + return [] if t.empty? move_string(t, a).concat(move_regexp(t, a)) end @@ -141,8 +142,6 @@ module ActionDispatch end def move_regexp(t, a) - return [] if t.empty? - t.flat_map { |s| if states = @regexp_states[s] states.map { |re, v| re === a ? v : nil } @@ -151,8 +150,6 @@ module ActionDispatch end def move_string(t, a) - return [] if t.empty? - t.map do |s| if states = @string_states[s] states[a] -- cgit v1.2.3 From ee453a1ea1e35a0ef2f9f65a135c9e5d090b3dd2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Apr 2014 15:55:48 -0700 Subject: do not create memo objects since we'll just throw them away --- actionpack/lib/action_dispatch/journey/gtg/simulator.rb | 17 ++++++++++------- actionpack/lib/action_dispatch/journey/router.rb | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/journey/gtg/simulator.rb b/actionpack/lib/action_dispatch/journey/gtg/simulator.rb index 254c2befc4..94b0a24344 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/simulator.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/simulator.rb @@ -19,6 +19,14 @@ module ActionDispatch end def simulate(string) + ms = memos(string) { return } + MatchData.new(ms) + end + + alias :=~ :simulate + alias :match :simulate + + def memos(string) input = StringScanner.new(string) state = [0] while sym = input.scan(%r([/.?]|[^/.?]+)) @@ -29,15 +37,10 @@ module ActionDispatch tt.accepting? s } - return if acceptance_states.empty? + return yield if acceptance_states.empty? - memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact - - MatchData.new(memos) + acceptance_states.flat_map { |x| tt.memo(x) }.compact end - - alias :=~ :simulate - alias :match :simulate end end end diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index 419e665d12..36561c71a1 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -121,8 +121,7 @@ module ActionDispatch def filter_routes(path) return [] unless ast - data = simulator.match(path) - data ? data.memos : [] + simulator.memos(path) { [] } end def find_routes env -- cgit v1.2.3 From 0e53d11b1fa9712270402afce771402c45fdd645 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Apr 2014 15:56:23 -0700 Subject: combine move_regexp and move_string so we only loop over states once --- .../lib/action_dispatch/journey/gtg/transition_table.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index 53c47f4696..821b510b9e 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -41,7 +41,7 @@ module ActionDispatch def move(t, a) return [] if t.empty? - move_string(t, a).concat(move_regexp(t, a)) + move_string(t, a) end def as_json(options = nil) @@ -141,20 +141,17 @@ module ActionDispatch end end - def move_regexp(t, a) - t.flat_map { |s| + def move_string(t, a) + regexps = [] + t.map { |s| if states = @regexp_states[s] - states.map { |re, v| re === a ? v : nil } + regexps.concat states.map { |re, v| re === a ? v : nil } end - }.compact.uniq - end - def move_string(t, a) - t.map do |s| if states = @string_states[s] states[a] end - end.compact + }.compact.concat regexps end end end -- cgit v1.2.3 From 6c6dc329f8ca87304bce3be79f4d1172219d07ad Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Apr 2014 15:58:42 -0700 Subject: push move_string in to `move` --- .../journey/gtg/transition_table.rb | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index 821b510b9e..990d2127ee 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -41,7 +41,18 @@ module ActionDispatch def move(t, a) return [] if t.empty? - move_string(t, a) + + regexps = [] + + t.map { |s| + if states = @regexp_states[s] + regexps.concat states.map { |re, v| re === a ? v : nil } + end + + if states = @string_states[s] + states[a] + end + }.compact.concat regexps end def as_json(options = nil) @@ -140,19 +151,6 @@ module ActionDispatch raise ArgumentError, 'unknown symbol: %s' % sym.class end end - - def move_string(t, a) - regexps = [] - t.map { |s| - if states = @regexp_states[s] - regexps.concat states.map { |re, v| re === a ? v : nil } - end - - if states = @string_states[s] - states[a] - end - }.compact.concat regexps - end end end end -- cgit v1.2.3