1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Replace map.flatten with flat_map in actionpack

This commit is contained in:
Erik Michaels-Ober 2014-03-03 19:23:12 -08:00
parent ffcc6172b4
commit 817fe31196
7 changed files with 18 additions and 18 deletions

View file

@ -27,7 +27,7 @@ module ActionDispatch
marked[s] = true # mark s marked[s] = true # mark s
s.group_by { |state| symbol(state) }.each do |sym, ps| s.group_by { |state| symbol(state) }.each do |sym, ps|
u = ps.map { |l| followpos(l) }.flatten u = ps.flat_map { |l| followpos(l) }
next if u.empty? next if u.empty?
if u.uniq == [DUMMY] if u.uniq == [DUMMY]
@ -90,7 +90,7 @@ module ActionDispatch
firstpos(node.left) firstpos(node.left)
end end
when Nodes::Or when Nodes::Or
node.children.map { |c| firstpos(c) }.flatten.uniq node.children.flat_map { |c| firstpos(c) }.uniq
when Nodes::Unary when Nodes::Unary
firstpos(node.left) firstpos(node.left)
when Nodes::Terminal when Nodes::Terminal
@ -105,7 +105,7 @@ module ActionDispatch
when Nodes::Star when Nodes::Star
firstpos(node.left) firstpos(node.left)
when Nodes::Or when Nodes::Or
node.children.map { |c| lastpos(c) }.flatten.uniq node.children.flat_map { |c| lastpos(c) }.uniq
when Nodes::Cat when Nodes::Cat
if nullable?(node.right) if nullable?(node.right)
lastpos(node.left) | lastpos(node.right) lastpos(node.left) | lastpos(node.right)

View file

@ -31,7 +31,7 @@ module ActionDispatch
return if acceptance_states.empty? return if acceptance_states.empty?
memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact
MatchData.new(memos) MatchData.new(memos)
end end

View file

@ -114,8 +114,8 @@ module ActionDispatch
end end
def states def states
ss = @string_states.keys + @string_states.values.map(&:values).flatten ss = @string_states.keys + @string_states.values.flat_map(&:values)
rs = @regexp_states.keys + @regexp_states.values.map(&:values).flatten rs = @regexp_states.keys + @regexp_states.values.flat_map(&:values)
(ss + rs).uniq (ss + rs).uniq
end end
@ -143,11 +143,11 @@ module ActionDispatch
def move_regexp(t, a) def move_regexp(t, a)
return [] if t.empty? return [] if t.empty?
t.map { |s| t.flat_map { |s|
if states = @regexp_states[s] if states = @regexp_states[s]
states.map { |re, v| re === a ? v : nil } states.map { |re, v| re === a ? v : nil }
end end
}.flatten.compact.uniq }.compact.uniq
end end
def move_string(t, a) def move_string(t, a)

View file

@ -16,9 +16,9 @@ module ActionDispatch
# end # end
# " #{n.object_id} [label=\"#{label}\", shape=box];" # " #{n.object_id} [label=\"#{label}\", shape=box];"
#} #}
#memo_edges = memos.map { |k, memos| #memo_edges = memos.flat_map { |k, memos|
# (memos || []).map { |v| " #{k} -> #{v.object_id};" } # (memos || []).map { |v| " #{k} -> #{v.object_id};" }
#}.flatten.uniq #}.uniq
<<-eodot <<-eodot
digraph nfa { digraph nfa {

View file

@ -34,7 +34,7 @@ module ActionDispatch
return if acceptance_states.empty? return if acceptance_states.empty?
memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact
MatchData.new(memos) MatchData.new(memos)
end end

View file

@ -42,7 +42,7 @@ module ActionDispatch
end end
def states def states
(@table.keys + @table.values.map(&:keys).flatten).uniq (@table.keys + @table.values.flat_map(&:keys)).uniq
end end
# Returns a generalized transition graph with reduced states. The states # Returns a generalized transition graph with reduced states. The states
@ -93,7 +93,7 @@ module ActionDispatch
# Returns set of NFA states to which there is a transition on ast symbol # Returns set of NFA states to which there is a transition on ast symbol
# +a+ from some state +s+ in +t+. # +a+ from some state +s+ in +t+.
def following_states(t, a) def following_states(t, a)
Array(t).map { |s| inverted[s][a] }.flatten.uniq Array(t).flat_map { |s| inverted[s][a] }.uniq
end end
# Returns set of NFA states to which there is a transition on ast symbol # Returns set of NFA states to which there is a transition on ast symbol
@ -107,7 +107,7 @@ module ActionDispatch
end end
def alphabet def alphabet
inverted.values.map(&:keys).flatten.compact.uniq.sort_by { |x| x.to_s } inverted.values.flat_map(&:keys).compact.uniq.sort_by { |x| x.to_s }
end end
# Returns a set of NFA states reachable from some NFA state +s+ in set # Returns a set of NFA states reachable from some NFA state +s+ in set
@ -131,9 +131,9 @@ module ActionDispatch
end end
def transitions def transitions
@table.map { |to, hash| @table.flat_map { |to, hash|
hash.map { |from, sym| [from, sym, to] } hash.map { |from, sym| [from, sym, to] }
}.flatten(1) }
end end
private private

View file

@ -53,9 +53,9 @@ module ActionDispatch
end end
def optional_names def optional_names
@optional_names ||= spec.grep(Nodes::Group).map { |group| @optional_names ||= spec.grep(Nodes::Group).flat_map { |group|
group.grep(Nodes::Symbol) group.grep(Nodes::Symbol)
}.flatten.map { |n| n.name }.uniq }.map { |n| n.name }.uniq
end end
class RegexpOffsets < Journey::Visitors::Visitor # :nodoc: class RegexpOffsets < Journey::Visitors::Visitor # :nodoc: